UIButton title disappears

前端 未结 5 1646
囚心锁ツ
囚心锁ツ 2021-01-20 03:52

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

相关标签:
5条回答
  • 2021-01-20 04:33

    With attributed text, make sure button Type = Custom (not System) in your storboard/xib.

    0 讨论(0)
  • 2021-01-20 04:34

    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:

    • select the button
    • in Attributes Inspector -> State Config -> select "highlighted"
    • select the correct "text color"
    0 讨论(0)
  • 2021-01-20 04:45

    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];
    
    0 讨论(0)
  • 2021-01-20 04:47

    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.

    0 讨论(0)
  • 2021-01-20 04:56

    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.

    0 讨论(0)
提交回复
热议问题