I am using NSLocalizedString function to change the language of a UIButton
reset.titleLabel.text=NSLocalizedString(@"Reset", nil);
I put this line in the viewDiLoad
, viewWillAppear
, viewDidAppear
, viewDidDisappear
and viewWillDisappear
when the View load , the localized version of the text appear , when I click on the button the text change back to the original text that is on the button in the Storyboard and then return to the localized language again right before loading the following view (even the the titlelable never changes values all across these stages!)
I saw that one of the solutions is to have a localized version of the Storyboard but I don t want to do that yest since I will have to maintain all localized versions ... any other solution ?
I would suggest using -setTitle:forState:
to change the title. By manually changing the titleLabel.text
, you should expect the text to be reset occasionally. Most documentation examples just show manipulating the font size, etc. not the contents, and that is because the titleLabel
is set to the currentTitle
Since there are multiple states for buttons, iOS has a way to set these where they are stored and to make sure that any image caches are appropriately updated.
[reset setTitle: NSLocalizedString( @"Reset", nil) forState: UIControlStateNormal];
As long as none of the other states are explicitly set, this will be used for all of the states. If you want to change the title for different states, use one of the other state contents.
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