I have a UIButton
, that when pressed, brings up a new view where the user can change some settings. When the view is dismissed, I'd like to update the title/text of the UIButton
to reflect the new state. I'm calling:
[myButton setTitle: @"myTitle" forState: UIControlStateNormal]; [myButton setTitle: @"myTitle" forState: UIControlStateApplication]; [myButton setTitle: @"myTitle" forState: UIControlStateHighlighted]; [myButton setTitle: @"myTitle" forState: UIControlStateReserved]; [myButton setTitle: @"myTitle" forState: UIControlStateSelected]; [myButton setTitle: @"myTitle" forState: UIControlStateDisabled];
But it never seems to change from the original text/title as specified in IB.
Programmatically. To make a multi-line text in UIButton, you insert a new line character ( \n ) wherever you want in button title and set lineBreakMode to byWordWrapping . You can adjust text alignment with . textAlignment .
You can omit UIControlState part and just write like button. setTitle("my text here", forState: . Normal) .
Open your storyboard and view controller source side by side in the assistant editor. Then select the label. Switch to the connections inspector and then drag from the small circle next to "New Referencing Outlet" and into the view controller source file. This should create the @IBOutlet for you.
I solved the problem just setting the title parameter for UIControlStateNormal, and it automatically works on the other states. The problem seems to be when you set another UIControlState.
[myButton setTitle: @"myTitle" forState: UIControlStateNormal];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With