循环创建按钮
2016-04-04 16:04
357 查看
#import "UserCell.h"
#define kBorderX 5 // 左边
#define kBorderY 0 // 上边
#define kMargin 5
#define kImageViewW ([UIScreen mainScreen].bounds.size.width - kBorderX * 2 - kMargin * 6 ) / 7
@interface UserCell ()
@property (nonatomic, strong) NSMutableArray *imageViewArr;
@end
@implementation UserCell
- (void)awakeFromNib {
[super awakeFromNib];
// Initialization code
[self.imageViewArr removeAllObjects];
for (NSInteger i = 0; i < 7; i++) {
CGFloat x = kBorderX + (kMargin + kImageViewW) * i;
UIImageView *imageView = [[UIImageView alloc] init];
imageView.frame = CGRectMake(x, kBorderY, kImageViewW, kImageViewW);
imageView.backgroundColor = [UIColor redColor];
imageView.userInteractionEnabled = YES;
[imageView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickImage:)]];
imageView.layer.cornerRadius = kImageViewW * 0.5;
imageView.layer.masksToBounds = YES;
[self.imageViewArr addObject:imageView];
[self.contentView addSubview:imageView];
}
}
#define kBorderX 5 // 左边
#define kBorderY 0 // 上边
#define kMargin 5
#define kImageViewW ([UIScreen mainScreen].bounds.size.width - kBorderX * 2 - kMargin * 6 ) / 7
@interface UserCell ()
@property (nonatomic, strong) NSMutableArray *imageViewArr;
@end
@implementation UserCell
- (void)awakeFromNib {
[super awakeFromNib];
// Initialization code
[self.imageViewArr removeAllObjects];
for (NSInteger i = 0; i < 7; i++) {
CGFloat x = kBorderX + (kMargin + kImageViewW) * i;
UIImageView *imageView = [[UIImageView alloc] init];
imageView.frame = CGRectMake(x, kBorderY, kImageViewW, kImageViewW);
imageView.backgroundColor = [UIColor redColor];
imageView.userInteractionEnabled = YES;
[imageView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickImage:)]];
imageView.layer.cornerRadius = kImageViewW * 0.5;
imageView.layer.masksToBounds = YES;
[self.imageViewArr addObject:imageView];
[self.contentView addSubview:imageView];
}
}
相关文章推荐
- 关于程序员职业生涯的若干问题思考
- EasyUI Datagrid JSON对象内嵌对象的取值问题
- Delphi GDI+基本用法总结
- [POJ 1637]Sightseeing tour[混合图欧拉回路]
- c获取系统时间及time time_t和gmtime
- Java Lock-同步的另一种实现
- PHP语言 -- 数组常用函数
- C++ 静态成员
- !improtant和*的css hack
- C语言穷举法
- APP生产和开发环境的分离(手把手教你)
- c里面位段分析
- Android 测试
- 如何使用java中的对象
- 逐步转向自己主动化測试
- python语言学习8——字符串和编码
- SIP请求消息类型与应答码
- Windows下的C/C++程序BUG现象与原因汇总
- PCL入门
- 杭电2539