• 循环创建按钮


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

            

        }

    }

    1
  • 相关阅读:
    [luogu3334]抛硬币
    [luogu3706]硬币游戏
    [luogu4548]歌唱王国
    [hdu4652]Dice
    [atAGC013F]Two Faced Cards
    [atAGC045F]Division into Multiples
    [atAGC045E]Fragile Balls
    [atAGC045D]Lamps and Buttons
    [luogu5574]任务分配问题
    [luogu4331]数字序列
  • 原文地址:https://www.cnblogs.com/fantasy3588/p/5352210.html
Copyright © 2020-2023  润新知