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

循环创建按钮

时间:2016-04-04 18:01:28      阅读:112      评论:0      收藏:0      [点我收藏+]

标签:

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

        

    }

 

}

 

循环创建按钮

标签:

原文地址:http://www.cnblogs.com/fantasy3588/p/5352210.html

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