循环创建btn及简单布局

 1 for(int i = 0; i < 12; i++)
 2     {
 3         button = [UIButton buttonWithType:UIButtonTypeCustom];
 4         button.frame = CGRectMake(width*(i%4), 64*(i/4), width, 64);
 5         button.imageEdgeInsets = UIEdgeInsetsMake(-10, 0, 0, 0);
 6         button.tag = 22000 + i;
 7         [button setBackgroundImage:[Util createImageWithColor:WHITE] forState:UIControlStateNormal];
 8         [button setBackgroundImage:[Util createImageWithColor:LIGHT_GRAY] forState:UIControlStateHighlighted];
 9         [button setImage:[UIImage imageNamed:[NSString stringWithFormat:@"easy_new_%d",i]] forState:UIControlStateNormal];
10         
11         [button addTarget:self action:@selector(easyBtn:) forControlEvents:UIControlEventTouchUpInside];
12         [scrollview addSubview:button];

 

posted @ 2016-01-11 17:03  欢欢0919  阅读(147)  评论(0)    收藏  举报