skyguy skyguy - 10 months ago 28
Swift Question

Swift: 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



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)