开发者

Localized XIB labels

开发者 https://www.devze.com 2023-03-14 16:13 出处:网络
I took a look in different post and articles, and of course the apple documentation, usually enough for localization purposes.

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 w开发者_如何学运维e retrieve the UILabel from the XIB file in the UIViewController (viewDidLoad)?

Thanks for your time,

Ivan


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(.., ..);


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 ?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号