博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
一个夭折,
阅读量:7069 次
发布时间:2019-06-28

本文共 2678 字,大约阅读时间需要 8 分钟。

-(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;

    

}

转载于:https://www.cnblogs.com/guligei/archive/2013/04/12/3016071.html

你可能感兴趣的文章
linux运维学习之ansib基础知识详解
查看>>
mysql备份脚本(转)
查看>>
14-思科防火墙:ASA对IP分片的处理
查看>>
C语言scanf函数用法详细解释!
查看>>
计算机操作系统启动和Linux boot
查看>>
读书笔记14:适配器模式
查看>>
Oracle实用-01:绑定变量
查看>>
我的友情链接
查看>>
扫描端口占用情况的python脚本
查看>>
STL::vector讲解
查看>>
没有银弹
查看>>
浅谈java.lang.ThreadLocal类
查看>>
梦想者市集:创业的核心能力(上)
查看>>
SSL卸载+IP保护(攻击)+异地容灾+横向扩展
查看>>
工匠精神需要职业通道的支持
查看>>
ubuntu 开机启动小键盘
查看>>
ORACLE-RMAN-自动恢复命令
查看>>
【LeetCode】409. Longest Palindrome (java实现)
查看>>
jquery form插件ajaxForm/ajaxSubmit时 IE8 提示下载
查看>>
ajax请求组件
查看>>