limon
limon

Reputation: 3212

How to change custom button's text?

I need to set text to the this custom button.I thought it would be as easy as using setText method to set its text. But, unfortunately, it doesn't work.

So, why this approach doesn't work for any custom buttons?

When we changed its type to custom, basically how it effects this UIButton?

Thank you.

EDIT: I've created this UIButton through IB. The code used for changing text is this :

  [self.btnDiscover setTitle:@"Discover" forState:UIControlStateNormal];

A Custom Button

Upvotes: 3

Views: 9050

Answers (1)

sergio
sergio

Reputation: 69037

Use setTitle:forState: instead of setText, e.g.:

[button setTitle:NSLocalizedString(@"CONTACT_BUTTON", @"Contact Us") forState:UIControlStateNormal];

Also, make sure you are using setBackgroundImage:forState: to set the button image and not setImage:forState:.

As to your question about the custom style, assigning UIButtonTypeCustom to a button simply means that the button is assigned no style (source):

UIButtonTypeCustom

No button style.

Upvotes: 4

Related Questions