zoukankan      html  css  js  c++  java
  • 一个夭折,

    -(IBAction)indexCityView:(id)sender

    {

        UIButton *button = (UIButton *)sender;

        int btnTag = button.tag;

        NSString *stopLetter;

        NSString *containLetter;

        switch (btnTag) {

            case 0:

                containLetter = @"ABCDE";

                stopLetter = @"F";

                break;

            case 1:

                containLetter = @"FJHIJ";

                stopLetter = @"K";

                break;

            case 2:

                containLetter = @"KLMNO";

                stopLetter = @"P";

                break;

            case 3:

                containLetter = @"PQRST";

                stopLetter = @"U";

                break;

            default:

                containLetter = @"UVWXYZ";

                stopLetter = @"a";//ascII a:97, Z:90

                break;

        }

       

        int rampage;//行数

        int column;//列数

        

        int buttonViewTag = 1110 ;//移出scrollview上面的 button,设置tag的起始值

        for (int i =buttonViewTag; i<1110 + self.cityList.count; i++) {

            [[self.viewviewWithTag:i] removeFromSuperview];

        }

        for (int i = 0; i<self.cityList.count ; i++) {

            BOOL jumpOutsideCircle = NO;

            HFCity *hfCity = (HFCity *)[self.cityList objectAtIndex:i];

            NSString *cStartLetter = hfCity.cityStartLetter;//获得起始字母

            BOOL isContainLetter = NO;

            NSRange range=[containLetter rangeOfString:cStartLetter];

            if(range.location!=NSNotFound){

                isContainLetter = YES;

            }

            

            NSString *nowLetter;

            NSString *nextLetter;

            int nextLine;

            BOOL nextLineFlag;

            if (isContainLetter) {

                for (int j = i; j<self.cityList.count; j++) {

                    jumpOutsideCircle = YES;//跳出外面for循环标志

                    hfCity = (HFCity *)[self.cityList objectAtIndex:j];

                    NSComparisonResult result = [hfCity.cityStartLetter compare:stopLetter];

                    BOOL compareResult = result == NSOrderedDescending ? YES:NO;

                    if ([hfCity.cityStartLetter isEqualToString:stopLetter] || compareResult == YES ) {

                        break; //跳出内部for循环

                    }

                    nextLetter = hfCity.cityName;

                    if (nextLineFlag) {

                        nextLine++;

                    }else{

                        nextLine = j;

                    }

                    //进一步剥离 abcde

                    if (![nowLetter isEqualToString:nextLetter]) {

                        nextLine = j+4-column;

                        nextLineFlag = YES;

                    }

                    UIButton *btn = [[UIButton alloc] init];

                    [UIButton buttonWithType:UIButtonTypeRoundedRect];                

                    [btn setTitle:hfCity.cityNameforState:UIControlStateNormal];

                    [btn setTitleColor:[UIColorcolorWithRed:128/255green:128/255blue:128/255alpha:1] forState:UIControlStateNormal];

                    [btn setTitleColor:[UIColorcolorWithRed:0/255.0green:132/255.0blue:26/255.0alpha:1] forState:UIControlStateHighlighted];

                    [btn addTarget:selfaction:@selector(chooseCity:) forControlEvents:UIControlEventTouchUpInside];

                    buttonViewTag++;

                    btn.tag = buttonViewTag;

                    

                   

                    rampage = (nextLine - i)/4;//541,541,454

                    column = (nextLine - i)%4;//

                    int x = column*70;

                    int y = rampage*30;

                    btn.frame = CGRectMake(x, y, 70, 30);

                    [self.cityScrollView addSubview:btn];

                    nowLetter = hfCity.cityName;

                    }

                

                if (jumpOutsideCircle) {

                    break;//跳出外部for循环

                }

     

            }

           

        }

        self.cityScrollView.contentSize = CGSizeMake(65*column, 50*rampage);//width,height

        self.cityScrollView.tag = 002;

        

    }

  • 相关阅读:
    qml----动画入门(六、简单的动画实现 SpringAnimation类)
    qml----动画入门(五、简单的动画实现 SmoothedAnimation类)
    qml----动画入门(四、简单的动画实现 PathAnimation类)
    qml----动画入门(三、简单的动画实现 RotationAnimation类)
    SSRS连接ORACLE数据库制作报表
    JavaScript Number 对象
    Django--filter()-字段查找(双下划线的使用详解)
    Django--filter(**kwargs)
    Django--QuerySet--基础查询
    python 内置函数
  • 原文地址:https://www.cnblogs.com/guligei/p/3016071.html
Copyright © 2011-2022 走看看