I have an UIButton in my View that says "STOP". When pressed, it should (stop the playback, of course, and) change its label to "RTN TO ZERO". This is straightforward:
stopButton.titleLabel.text = @"RTN TO ZERO";
However, the change appears only for a split second. It doesn't stick. I assume that the button (which gets highlighted when pressed) accepts and displays the new label, but somehow the highlight is reversed only later, restoring the button to the look it had before it was pressed, not honoring the label text change. The button is conceived in IB, not programmatically.
I feel stupid. Can someone please point me in the right direction?
In the button handler, try this:
[stopButton setTitle:@"RTN TO ZERO" forState:UIControlStateNormal];
Instead of directly changing text
property of titleLabel
use setTitle:forState:
method to set the title in different states. Please check the manual for the details of available states.
Swift version
myButton.setTitle("button text", for: UIControl.State.normal)
Use setAttributedTitle:for
for attributed text. See here for how to make attributed strings in Swift.
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