Change color of text when button is pushed? Change color of text when button is pushed? ios ios

Change color of text when button is pushed?


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)


Swift 3.0 example:

    colorsBtn.setTitleColor(UIColor .white, for: UIControlState.normal)    colorsBtn.setTitleColor(UIColor .black, for: UIControlState.highlighted)