在运行时在本地化故事板之间切换

时间:2013-01-10 14:02:31

标签: iphone ios localization storyboard xcode-storyboard

我有使用两种语言(阿拉伯语/英语)的故事板的iPhone应用程序如何从阿拉伯语本地化故事板切换到英语故事板,而无需更改语言iPhone设置(在运行时)

1 个答案:

答案 0 :(得分:8)

我已经解决了您可以按照以下代码执行此操作:

 UIStoryboard *storyBoard;
 if ([language isEqualToString:@"ar"]) {
   lan = [[NSLocale preferredLanguages] objectAtIndex:0];
   storyBoard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone5Arabic" bundle:bnd];
 }
 else if([language isEqualToString:@"en"]) {
    NSLog(@"DDD ");
    lan = [[NSLocale preferredLanguages] objectAtIndex:20];
    storyBoard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone5English" bundle:bnd];
 }
 NSBundle *bnd = [NSBundle bundleWithPath:[[NSBundle mainBundle]pathForResource:lan ofType:@"lproj" ]];



UIViewController *initViewController = [storyBoard instantiateInitialViewController];
[self.window setRootViewController:initViewController];