UIButton常用属性总结

UIButton经常用到的属性

参考:http://www.bubuko.com/infodetail-656634.html


- (void)buildUI{

    //初始化

    CGRect btnControlRect=CGRectMake(200,200, 100,30);

    UIButton *btnControl = [UIButtonbuttonWithType:UIButtonTypeCustom];

    btnControl.frame = btnControlRect;

    

   //圆角

    btnControl.layer.cornerRadius =5;

    btnControl.layer.masksToBounds =YES;

    

   // 设置按钮的setBackgroundImage

    [btnControlsetBackgroundImage:[UIImageimageNamed:@"desc_nomal.png"]forState:UIControlStateNormal];

    [btnControlsetBackgroundImage:[UIImageimageNamed:@"desc_nomal.png"]forState:UIControlStateHighlighted];

    [btnControlsetBackgroundImage:[UIImageimageNamed:@"desc_nomal.png"]forState:UIControlStateSelected];

    [btnControlsetBackgroundColor:[UIColorclearColor]];


   //设置按钮的textcolor

    [btnControlsetTitle:@"预定"forState:UIControlStateNormal];

    [btnControlsetTitle:@"取消"forState:UIControlStateSelected];

    

    [btnControlsetTitleColor:[UIColorcolorWithRed:50/255.0green:50/255.0blue:50/255.0alpha:1.0]forState:UIControlStateNormal];

    [btnControlsetTitleColor:[UIColorcolorWithRed:255/255.0green:255/255.0blue:255/255.0alpha:1.0]forState:UIControlStateSelected];

   // 行数,字号

    [btnControl.titleLabelsetNumberOfLines:2];

    [btnControl.titleLabelsetFont:[UIFontsystemFontOfSize:14]];

   // 设置按钮文本对齐方式

    btnControl.titleLabel.textAlignment =NSTextAlignmentCenter;

    

   // 设置按钮图片和文字的相对位置 (topleftbottomright)

    UIImage *image = [UIImageimageNamed:@""];

    btnControl.titleEdgeInsets =UIEdgeInsetsMake(0, -(image.size.width),0, 0);//文字在右

    btnControl.imageEdgeInsets =UIEdgeInsetsMake(0,0, 0, btnControl.frame.size.width-image.size.width);//图片在左

    //设置按钮的内部内容(包含按钮图片和标题)离按钮边缘上左下右的距离。

    btnControl.contentEdgeInsets =UIEdgeInsetsMake(0,0, 0,0);

    

    [btnControladdTarget:selfaction:@selector(ClickControlAction:)forControlEvents:UIControlEventTouchUpInside];

    

    [self.viewaddSubview:btnControl];

    


}

//点击事件

- (void)ClickControlAction:(UIButton *)button{

    if (button.selected!=YES) {

        button.selected=YES;

    }else{

        button.selected=NO;

    }

}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值