I’ve subclassed UIButton and am trying to set the title colour when the button is highlighted. The custom button is also on a nib file.
I have the code:
- (void)layoutSubviews
{
[super layoutSubviews];
self.titleLabel.textColor = [UIColor blueColor];
[self setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted]; // Offending line
}
However, the view does not load (seemingly goes into an infinite loop and doesn’t show) when I have the setTitleColor:forState: line. Is it supposed to be declared elsewhere? How else do you set the highlighted title colour of a custom UIButton?
If you want to do this in layoutSubviews, this will avoid the infinite loop you are currently creating: