美文网首页UIButton
循环创建按钮

循环创建按钮

作者: 失忆的程序员 | 来源:发表于2019-02-22 18:02 被阅读0次

- (void)setHomeFooterViewOne {

    // 一个图片的高度 margin20 = 20 像素点

    CGFloatbgViewHh = (kScreenWidth-margin20*2)/3;

    // 底部view  20 20

    UIView*bgView = [[UIViewalloc]initWithFrame:CGRectMake(0,0,kScreenWidth, bgViewHh*2)];

    bgView.backgroundColor = BGColor;

    [selfaddSubview:bgView];

    for(inti =0; i <6; i++) {

        inta = i/3;  //取余

        intb = i%3;  //取整

        UIButton*tagButton = [[UIButtonalloc]initWithFrame:CGRectMake(margin20+ bgViewHh * b, bgViewHh * a, bgViewHh, bgViewHh)];

        tagButton.layer.borderColor=redColor1.CGColor;

        tagButton.layer.borderWidth=1;

        tagButton.layer.cornerRadius=5;

        tagButton.tag= i;

        tagButton.titleLabel.font= [UIFontsystemFontOfSize:12];

        [tagButtonsetTitle:@"i" forState:UIControlStateNormal];

        [tagButtonsetTitleColor:BGColor forState:UIControlStateNormal];

        [tagButtonaddTarget:self action:@selector(tagButtonAction:) forControlEvents:UIControlEventTouchUpInside];

        [selfaddSubview:tagButton];

    }

}

- (void)tagButtonAction:(UIButton*)btn {

    XPFLog(@" --------- ----------- --------- ");

}

相关文章

网友评论

    本文标题:循环创建按钮

    本文链接:https://www.haomeiwen.com/subject/igtyyqtx.html