UIButton

1.基础设置(颜色、字体等)

_button = [[UIButton alloc] init];
//背景颜色
_button.backgroundColor = [UIColor brokerWhiteColor];
[_button setTitleColor:[UIColor brokerOrangeColor] 
forState:UIControlStateNormal];
//文字颜色
_button.titleLabel.font = [UIFont systemFontOfSize:14];//字体
//圆角
_button.layer.masksToBounds = YES;
_button.layer.cornerRadius = 10;
//图片(默认在左)
[_button setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];

2.图片和文字的位置

图片在右

NSString *str = @"";
CGFloat titleWidth = [str sizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14]}].width;
[self.button setTitle:str forState:UIControlStateNormal];
CGFloat space = 5;
CGFloat imageWidth = 13;
[self.button setTitleEdgeInsets:UIEdgeInsetsMake(0, -imageWidth, 0, imageWidth)];
[self.button setImageEdgeInsets:UIEdgeInsetsMake(0, titleWidth + space, 0, -titleWidth-space)];

其他(详细):http://www.cocoachina.com/ios/20171218/21574.html

你可能感兴趣的:(UIButton)