Reputation: 1926
I am creating a custom button with multiple labels. I want to be able to change the text color of the labels on highlight/normal UIControlStates. I know its possible to change the title text color based on control states, but I can't seem to figure it out for custom labels within the button. Any ideas?
Upvotes: 1
Views: 2881
Reputation: 1926
Thanks for the idea @Rich. I subclassed UIButton and put this code in the new class.
Heres the code I used:
- (void)setHighlighted:(BOOL)bHighlighted
{
[super setHighlighted:bHighlighted];
if (bHighlighted) {
[label1 setTextColor:[UIColor whiteColor]];
[label2 setTextColor:[UIColor whiteColor]];
}else {
[label1 setTextColor:[UIColor blackColor]];
[label2 setTextColor:[UIColor blackColor]];
}
}
Upvotes: 2