Changing the button text color when selected

20,923

Solution 1

You can do it this way:

[myButton setTitleColor:[UIColor greenColor] forState:UIControlStateHighlighted];

Solution 2

Swift version:

myButton.setTitleColor(UIColor.greenColor(), forState: UIControlState.Highlighted)

Solution 3

You could also achieve this with storyboards by selecting in the attributes inspector under Button the State Config to Selected or Highlighted and style the button right there - no code needed :)

Share:
20,923

Related videos on Youtube

Abhinav
Author by

Abhinav

Updated on July 09, 2022

Comments

  • Abhinav
    Abhinav almost 2 years

    I have a custom button and I am setting the different image when it is highlighted. Now, I want to change the color of the text on the button when button is highlighted. Is it possible to do this?

  • Developer1205
    Developer1205 over 7 years
    Where can i add this code ...ViewDidLoad or Action method