Olex
Olex

Reputation: 1656

UIbutton label property

Just start to using Xcode. I made an IBOutlet from UIButton to have a possibility to change title with changing a localization setting. I try this code to do this

_loginButton.titleLabel.text = NSLocalizedString(@"Login", nil);

But this code does not set the button title. Do I need to use another kind of property?

Thank you very much for answering!

Upvotes: 0

Views: 167

Answers (2)

Mark Adams
Mark Adams

Reputation: 30846

You need to supply a UIControlState to set the title for.

[_loginButton setTitle:NSLocalizedString(@"Login", nil) forState:UIControlStateNormal];

Upvotes: 4

pixelfreak
pixelfreak

Reputation: 17834

For UIButton, try setting the title like this:

[self.loginButton setTitle:NSLocalizedString(@"Login", nil) forState:UIControlStateNormal];

There are other states as documented here

But if you don't specify the title for those states, they will use the normal state by default.

Upvotes: 2

Related Questions