2 for 2012 for_2012 于 2013.02.28 13:54 提问

添加两个xib文件支持iphone屏幕

请教一个关于iphone屏幕尺寸的问题,

我创建了两个xib文件(MainWindow.xibMainWindowiPhone5.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都能正常运行呢?

1个回答

redCoral_
redCoral_   2013.02.28 14:40
已采纳

应该是这样:

iPhone-4S屏幕:

 if ([[UIScreen mainScreen] bounds].size.height == 480)
 {
   ---- Your Code ----
 }

iPhone-5 屏幕:

 if ([[UIScreen mainScreen] bounds].size.height == 568)
 {
   ---- Your Code ----
 }
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!