user3692917
user3692917

Reputation:

Change color of UIButton in selected state

I have a button that when tapped changes between favorite and unfavorite. When it is tapped I change its state to selected. With this code:

button.selected = YES;

So when it is unselected it looks like this:

Then the selected version looks like this:enter image description here

I want the text in the selected version to be white. I know how to change the background color with this code:

[_favourite setTintColor:[UIColor whiteColor]];

But I want to change the elected version so that the text inside is white.

Thanks a bunch for the help in advance.

Upvotes: 5

Views: 6255

Answers (1)

Dko
Dko

Reputation: 830

Does this UIButton API accomplish what you are trying to achieve?

[_favourite setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];

Upvotes: 4

Related Questions