Stop UIButton's custom reload titleLabel on IB by default when the event fires

In IB, I have a view with a UIButton of type Custom, it has no image, and the Title is set to "#placeholder"

The view is attached to a class that provides IBOutlet and IBAction buttons for a button.

I set the button title as follows: ViewClass.ButtonOutlet.titleLabel.text = @"%@",stringifiedVariable; whenever I need.

This is working fine. However, when I click the button, the title titleLabel.text returns to "#placeholder".

I tried to uncheck the box underlined to adjust the image in the Drawing section (attributes tab) in the Inspector, but everything was still.

Can this change be prevented? or is there a better model i should use?

+7
objective-c cocoa-touch ipad
source share
2 answers

UIButton has a special method for setting labels.

  • (void) setTitle: (NSString *) title forState: (state UIControlState)

for example

 NSString *buttonText = [NSString stringWithFormat:@"%@",stringifiedVariable]; [ViewClass.ButtonOutlet setTitle:buttonText forState:UIControlStateNormal]; 

See the documentation for more details.

+12
source share

If you want the text to not change when you click on it, the easiest way is to take the name from the button in IB, and then use the setTitle: forState: method from Jongsma.

0
source share

All Articles