[英]Load different view for iphone 4, iphone 5 and greater, ipad
I currently have the below code that loads the view depending on if the device is and ipad or iphone, however I need to change it to have three different options. 我目前有以下代码,根据设备是iPad,ipad还是iphone加载视图,但是我需要对其进行更改以具有三个不同的选项。
A view for iphone 4, and view for iphone 5 and greater and then view for ipad iPhone 4的视图,iPhone 5及更高版本的视图,然后iPad的视图
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPhone" bundle:nil];
self.navController= [[UINavigationController alloc] initWithRootViewController:self.viewController];
} else
{
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPad" bundle:nil];
self.navController= [[UINavigationController alloc] initWithRootViewController:self.viewController];
}
This is very easy indeed. 确实,这很容易。 You can do it, by checking the screen sizes and then deciding what view to show, like so:
您可以执行以下操作:检查屏幕尺寸,然后确定要显示的视图,如下所示:
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
CGSize result = [[UIScreen mainScreen] bounds].size;
NSString *viewName;
if (result.height == 480) {
// 3.5 inch display - Iphone 4S and below
viewName = [NSString stringWithFormat:@"ViewController_iPhone_SMALL"];
}
else if (result.height == 568) {
// 4 inch display - iPhone 5
viewName = [NSString stringWithFormat:@"ViewController_iPhone_5"];
}
else if (result.height == 667) {
// 4.7 inch display - iPhone 6
viewName = [NSString stringWithFormat:@"ViewController_iPhone_6"];
}
else if (result.height == 736) {
// 5.5 inch display - iPhone 6 Plus
viewName = [NSString stringWithFormat:@"ViewController_iPhone_6_PLUS"];
}
self.viewController = [[ViewController alloc] initWithNibName:viewName bundle:nil];
self.navController= [[UINavigationController alloc] initWithRootViewController:self.viewController];
}
else {
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPad" bundle:nil];
self.navController= [[UINavigationController alloc] initWithRootViewController:self.viewController];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.