使用2个不同的故事板,一个用于LTR,一个用于RTL(非自动布局)

时间:2014-12-21 11:34:38

标签: ios objective-c storyboard

我的应用现在支持 RTL 语言,我想添加对 LTR 语言的支持。 我创建了额外的storyboard文件,并设置了所有标签,按钮,图片等的对齐方式,以支持 LTR

现在,我如何知道使用 LTR 语言的用户以及如何告诉应用使用 LTR 故事板?

我尝试使用自动布局 - 但没有成功。

所以我决定这样做,任何想法?

1 个答案:

答案 0 :(得分:0)

您可以在app delegate中尝试此操作:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];

  UIStoryboard *storyboard;

  // Determine the text direction and load the Storyboard accordingly
  if ([UIApplication sharedApplication].userInterfaceLayoutDirection == UIUserInterfaceLayoutDirectionRightToLeft) {
    storyboard = [UIStoryboard storyboardWithName:@"RTL" bundle:nil];
  } else {
    storyboard = [UIStoryboard storyboardWithName:@"LTR" bundle:nil];
  }

  // Get the initial view controller
  UIViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:@"InitialViewController"];

  self.window.rootViewController = viewController;
  [self.window makeKeyAndVisible];

  return YES;
}
相关问题