문제

I'm working on a universal iOS app and wanting to use different xib files for iPhone 5. The way it currently works is by automatically selecting the file with the right device modifier (as specified here: http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/LoadingResources/Introduction/Introduction.html#//apple_ref/doc/uid/10000051i-CH1-SW2). However there's no mention there of how to handle the iPhone 5. I'm surprised because I'm under the impression they'd prefer developers to create a different/unique experience on the 5 instead of just auto scaling...

Anyone aware of a modifier that works? (eg myxib~iphone5.xib) It would be more convenient than having to handle the device detection and switching myself.

Cheers!

도움이 되었습니까?

해결책

There's no naming convention unfortunately, but there's a way. This is what I'm using:

I have a global .h file called GlobalConstants that I put all my #define macros in. There I have this:

static BOOL is4InchRetina()
{
    if ((![UIApplication sharedApplication].statusBarHidden && (int)[[UIScreen mainScreen] applicationFrame].size.height == 548) || ([UIApplication sharedApplication].statusBarHidden && (int)[[UIScreen mainScreen] applicationFrame].size.height == 568))
        return YES;

    return NO;
}

then in any of my view controller classes - I override the init method like this:

#import GlobalConstants.h

-(id) init {

if(is4InchRetina()) self = [super initWithNibName:@"myNibName5" bundle:[NSBundle mainBundle]];
else self = [super initWithNibName:@"myNibName" bundle:[NSBundle mainBundle]];

return self
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top