Joj*_*dmo -1 objective-c xib nib
有没有办法检测用户使用的设备,然后使用该信息,使应用程序使用特定的nib文件?
现在,我的代码是
- (BOOL)application: (UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions{
if(isiPhone5){
self.RootViewController = @"RootViewController_iPhone5";
}
else{
self.RootViewController = @"RootViewController_iPhone4";
}
}
Run Code Online (Sandbox Code Playgroud)
我找到设备的其他代码可以工作并告诉我用户正在使用什么设备,但实际上并没有将.xib文件更改RootViewController_iPhone4.xib为RootViewController_iPhone5.xib.有没有办法做到这一点?
我不想使用自动布局,因为我想根据设备发生其他自定义事件,例如视图控制器中的不同按钮名称,如果使用的设备是iPhone 4和iPhone 5
试试这种方式..
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
{
CGRect screenBounds = [[UIScreen mainScreen] bounds];
if (screenBounds.size.height ==568)
{
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPhone5" bundle:nil];
}
else
{
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPhone4" bundle:nil];
}
Run Code Online (Sandbox Code Playgroud)
更新的答案
检查这个... 用于屏幕检测的黑屏