您的位置:首页 > 其它

循环创建按钮

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

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: