Iván Peralta
Iván Peralta

Reputation: 851

Localized XIB labels

I took a look in different post and articles, and of course the apple documentation, usually enough for localization purposes.

But, I'm a newbie using IB.

In order to localize the XIB files, I know you can create one version for each language ... but anybody knows if is posible to manage from the UIViewController.

I prefer to manage the localization using the .strings file against to create different XIB files for every new language.

Could we retrieve the UILabel from the XIB file in the UIViewController (viewDidLoad)?

Thanks for your time,

Ivan

Upvotes: 0

Views: 1705

Answers (2)

Charles Vu
Charles Vu

Reputation: 468

I didn't test it but can we just subclass UILabel and overload the

- (void) setText:(NSString*) theString

method to

- (void) setText:(NSString*) theString
{
    [super setText: NSLocalizedString (theSrting);
}

Or something like this ?

Upvotes: 0

Deepak Danduprolu
Deepak Danduprolu

Reputation: 44633

You can't alter a XIB file but by the time viewDidLoad is called, the UILabel if it was part of the XIB file that the view controller loaded will already be part of the view hierarchy. Unless you've directly set an IBOutlet for the UILabel instance, you will have to search through the view hierarchy for a specific marker like a tag perhaps. Once you get the label, it should be a direct assignment of the localized string.

label.text = NSLocalizedString(.., ..);

Upvotes: 2

Related Questions