Joe Völker Joe Völker - 1 year ago 100
iOS Question

Text change on UIButton doesn't stick

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?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download