UIButton

循环创建按钮

2019-02-22  本文已影响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(@" --------- ----------- --------- ");

}

上一篇 下一篇

猜你喜欢

热点阅读