iOS Button设置

UIButton *kefuBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 60, 44)];
kefuBtn.backgroundColor = SXColor(248, 248, 248); // 设置按钮背景颜色
[kefuBtn setImage:[UIImage imageNamed:@"details_server"] forState:UIControlStateNormal];
[kefuBtn setImageEdgeInsets:UIEdgeInsetsMake(5, 8, 20, 5)]; // 设置图片位置
[kefuBtn setTitle:@"联系客服" forState:UIControlStateNormal];
kefuBtn.titleEdgeInsets = UIEdgeInsetsMake(30,-20, 10, 0);  // 设置文字位置
[kefuBtn setTitleColor:SXColor(149, 149, 149) forState:UIControlStateNormal]; //设置文字颜色
kefuBtn.titleLabel.font = [UIFont systemFontOfSize:12];  // 设置文字大小

效果如下:

原文地址:https://www.cnblogs.com/xsphehe/p/5672939.html