請教一個關於iphone屏幕尺寸的問題,
我創建了兩個xib文件(MainWindow.xib
和MainWindowiPhone5.xib
)。這樣我的屏幕就可以支持兩種屏幕尺寸。
我試過在AppDelegate.m
中編程,但是沒有實現。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){
UIStoryboard *storyBoard;
CGSize result = [[UIScreen mainScreen] bounds].size;
CGFloat scale = [UIScreen mainScreen].scale;
result = CGSizeMake(result.width * scale, result.height * scale);
if(result.height == 1136){
storyBoard = [UIStoryboard storyboardWithName:@"MainWindowiPhone5" bundle:nil];
UIViewController *tabBarController = [storyBoard instantiateInitialViewController];
[self.window.rootViewController = self.tabBarController];
}
}
return YES;
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
// Set the tab bar controller as the window's root view controller and display.
self.window.rootViewController = self.tabBarController;
tabBarController.moreNavigationController.navigationBar.tintColor = [UIColor blackColor];
[self.window makeKeyAndVisible];
return YES;
}
如何讓兩個xib都能正常運行呢?
應該是這樣:
iPhone-4S屏幕:
if ([[UIScreen mainScreen] bounds].size.height == 480)
{
---- Your Code ----
}
iPhone-5 屏幕:
if ([[UIScreen mainScreen] bounds].size.height == 568)
{
---- Your Code ----
}