对于部署目标为 iOS 5 和故事板的应用程序,我使用类似这样的东西来本地化我的选项卡,其中我在故事板上的第一个 ViewController 是UITabBarController
:
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// ...
if ([self.window.rootViewController isKindOfClass:UITabBarController.class]) {
UITabBarController *tabBarController = (UITabBarController *) self.window.rootViewController;
// Localize tab items
NSArray *tabBarItems = tabBarController.tabBar.items;
[tabBarItems enumerateObjectsWithOptions:NSEnumerationConcurrent
usingBlock:^(UITabBarItem *item, NSUInteger tabIndex, BOOL *stop) {
NSString *keyName = [NSString stringWithFormat:@"tabBarItem%i", tabIndex];
item.title = NSLocalizedString(keyName, @"TabBarItems");
}];
} else {
// The root view controller is not the UITTabBarController
}
// ...
}
并在我的Localizable.strings
文件中有这样的东西:
// MARK: TabBar
"tabBarItem0" = "My First Tab Label";
"tabBarItem1" = "My Second Tab Label";
"tabBarItem2" = "My Third Tab Label";