码迷,mamicode.com
首页 > 其他好文 > 详细

九宫格

时间:2015-12-11 14:47:49      阅读:114      评论:0      收藏:0      [点我收藏+]

标签:

 1   //完成布局设计
 2     
 3     //三列
 4     int totalloc=3;
 5     // 宽度
 6     CGFloat appvieww=85;
 7     //高度
 8     CGFloat appviewh=30;
 9     
10     CGFloat margin=(WIDTHW-totalloc*appvieww)/(totalloc+1);
11     CGFloat marginY=10;
12     for (int i=0; i<self.allarray.count; i++) {
13         int row=i/totalloc;//行号
14         //1/3=0,2/3=0,3/3=1;
15         int loc=i%totalloc;//列号
16         
17         CGFloat appviewx=margin+(margin+appvieww)*loc;
18         CGFloat appviewy=marginY+(marginY+appviewh)*row;
19         
20         //创建地区按钮
21         UIButton *regionBtn=[[UIButton alloc] initWithFrame:CGRectMake(appviewx, appviewy+64, appvieww, appviewh)];
22         [self.view addSubview:regionBtn];
23         //regionBtn.backgroundColor=[UIColor greenColor];
24         NSLog(@"#####buttons###allarray###%@",self.allarray[i]);
25         regionBtn.titleLabel.font=[UIFont systemFontOfSize:12];
26         RegionModel *regionModel=[[RegionModel alloc] init];
27         regionModel=_allarray[i];
28         [regionBtn setTitle:regionModel.name forState:UIControlStateNormal];
29         [regionBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
30         [regionBtn addTarget:self action:@selector(didClickRegion) forControlEvents:UIControlEventTouchUpInside];
31         
32     }

 

九宫格

标签:

原文地址:http://www.cnblogs.com/zcl410/p/ios.html

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