0

我想更改 UIButton 中标题的背景颜色(仅限!),其中包含标题和图像。

我只能看到如何更改为整个按钮的背景颜色,这不是我想要的。

任何想法 ?

4

3 回答 3

5

您需要设置titleLabel的背景颜色:

btn.titleLabel?.backgroundColor = UIColor.red
于 2018-02-26T10:10:03.693 回答
0

完整的答案是:

 btn.tintColor = UIColor.clear  //if we have different tint, which I had 
 btn.titleLabel?.backgroundColor = UIColor.clear
于 2018-03-04T09:45:16.763 回答
-1

要更改按钮标题颜色:

btn.setTitleColor(UIColor.yourColor, for: .normal)
于 2018-02-26T10:33:13.770 回答