I know how to change the background color but what about the actual text? There doesn't seem to be a member on a UIButton called "color" or anything like that. My code:
我知道如何改变背景颜色,但是实际的文本呢?似乎UIButton中没有一个成员叫做"color"或类似的东西。我的代码:
@IBAction func yellowBtnClicked(sender: UIButton) {
gameboard.image = UIImage(named: "Yellow_gb")
resultsView.image = UIImage(named: "Yellow_results")
colorsView.image = UIImage(named: "Yellow_colors")
colorsBtn.color = UIColor.brownColor() //This line has the issue
}
2 个解决方案
#1
59
There is no property setter color
in UIButton
. use instead setTitleColor
.Write this in viewWillAppear
UIButton中没有属性setter颜色。使用相反setTitleColor。写这篇文章进行处理
colorsBtn.setTitleColor(UIColor.brownColor(), forState: UIControlState.Normal)
This will change title color to brown for UIControlState.Normal
这将把uicontrolstate的标题颜色改为棕色
To set the color of title
when button is in Highlighted
state use
当按钮处于突出显示状态时,设置标题的颜色
colorsBtn.setTitleColor(UIColor.brownColor(), forState: UIControlState.Highlighted)
#2
6
Swift 3.0 example:
斯威夫特3.0的例子:
colorsBtn.setTitleColor(UIColor .white, for: UIControlState.normal)
colorsBtn.setTitleColor(UIColor .black, for: UIControlState.highlighted)
#1
59
There is no property setter color
in UIButton
. use instead setTitleColor
.Write this in viewWillAppear
UIButton中没有属性setter颜色。使用相反setTitleColor。写这篇文章进行处理
colorsBtn.setTitleColor(UIColor.brownColor(), forState: UIControlState.Normal)
This will change title color to brown for UIControlState.Normal
这将把uicontrolstate的标题颜色改为棕色
To set the color of title
when button is in Highlighted
state use
当按钮处于突出显示状态时,设置标题的颜色
colorsBtn.setTitleColor(UIColor.brownColor(), forState: UIControlState.Highlighted)
#2
6
Swift 3.0 example:
斯威夫特3.0的例子:
colorsBtn.setTitleColor(UIColor .white, for: UIControlState.normal)
colorsBtn.setTitleColor(UIColor .black, for: UIControlState.highlighted)