Switching between localized storyboard at runtime

前端 未结 1 1378
Happy的楠姐
Happy的楠姐 2021-02-04 14:21

I have iPhone application using storyboard with two language (Arabic / English) how i can switch from Arabic localization storyboard to English storyboard without need to change

1条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-04 14:43

    I have resolved you can do it as the following below code :

     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];
    

    0 讨论(0)
提交回复
热议问题