skyguy skyguy - 2 years ago 93
Swift Question

Change color of text when button is pushed?

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:

@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


Answer Source

There is no property setter color in UIButton. use instead setTitleColor.Write this in viewWillAppear

colorsBtn.setTitleColor(UIColor.brownColor(), forState: UIControlState.Normal)

This will change title color to brown for UIControlState.Normal

To set the color of title when button is in Highlighted state use

colorsBtn.setTitleColor(UIColor.brownColor(), forState: UIControlState.Highlighted)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download