I have a ViewController with an UIButton inside. When I clicked, the text on the button disappeared. I add all the setTitle for all states, but it continues disappearing. An
With attributed text, make sure button Type = Custom (not System) in your storboard/xib.
As Jack says, it's the "selected" state of the button that has got the same color of the background. You can change that color also in the Storyboard:
Well it's hard to say for sure, but is the text not visible because the color is the same? I see you set the text for all states but you may want to set the color for all states as well.
[commit setTextColor:[UIColor redColor] forState:UIControlStateSelected];
I guess you need to use [self.commit setTitle: NSLocal...
, actually use self.commit overall for assignments (when you use @property (nonatomic, retain)
or strong
with ARC). I use @synthesize commit = _commit;
and then only _commit for all the rest of the module.
I noticed a peculiar thing. If I set the title using
bttn.titleLabel.textColor = [UIColor purpleColor];
Then as soon as I click the button, the title disappears. But, if I use the following method :
[bttn setTitleColor:[UIColor purpleColor] forState:UIControlStateNormal];
Then everything is working correctly.