码迷,mamicode.com
首页 > 移动开发 > 详细

iOS实现row行column列个按钮的添加

时间:2015-05-26 22:42:40      阅读:138      评论:0      收藏:0      [点我收藏+]

标签:

注释要添加的按钮的总个数为total 
-(void)addScrollAndButton{

    

    int  COLUMN=4;//列数

    int total = self.listArray.count;

    //int rows = (total / COLUMN) + ((total % COLUMN) > 0 ? 1 : 0);

    

    int btnwidth=50;

    int btnheight=30;

    int widthblank=20;

    int heightblank=20;

 

    for (int i=0; i<total; i++) {

        int row = i / COLUMN;//行数

        int column = i % COLUMN;//列数

        

        //添加按钮

        UIButton *aButton=[UIButton buttonWithType:UIButtonTypeCustom];

        aButton.frame=CGRectMake((widthblank+btnwidth)*column, (heightblank+btnheight)*row, btnwidth, btnheight);

        aButton.tag=1000+i;

        [aButton setTitle:[[[self.listArray objectAtIndex:i]objectForKey:@"Table"]objectForKey:@"Title"] forState:UIControlStateNormal];

        [aButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];

        [aButton setShowsTouchWhenHighlighted:YES];//按的时候设置高亮

        [aButton addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];

        [self.view addSubview:aButton];

    }

 

}

-(void)buttonPressed:(id)sender

{

    UIButton * button = (UIButton *)sender;

    int index=button.tag-1000;

}

 

iOS实现row行column列个按钮的添加

标签:

原文地址:http://www.cnblogs.com/huangzs/p/4531695.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!