How to make xib compatible with both iphone 5 and iphone 4 devices

前端 未结 14 1797
执念已碎
执念已碎 2020-11-28 20:39

I am trying to layout my xib so that layout fits in both iphone 5 (4 inches retina) and 3.5 devices.

Because I have to support IOS-5 I cannot use autolayout. I have

14条回答
  •  [愿得一人]
    2020-11-28 21:10

    If you go with the solution of using 2 xib files; in your initWithNibName() method simply make a call to super with the different nib name.

    I would test on the original 480 height dimension rather than on the 568 height so that the larger xib file is selected when Apple releases a larger screen. In the future, at least the larger xib won't be letter-boxed as much as the smaller one.

    // From MainView.m
    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
    {
        CGSize result = [[UIScreen mainScreen] bounds].size;
        if(result.height == 480)
        {
            // iPhone Classic
            self = [super initWithNibName:@"MainView" bundle:nibBundleOrNil];
        }
        else
        {
            // iPhone 5 or maybe a larger iPhone ??
            self = [super initWithNibName:@"MainView5" bundle:nibBundleOrNil];
        }
    
        return self;
    }
    

提交回复
热议问题