How to make xib compatible with both iphone 5 and

2020-01-25 13:35发布

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 to use springs and Struts.

I tried everything in interface-builder. But either my view is going beyond the bottom of iphone-3.5-inch or not filling completely the iphone-4-inch-retina.

Can someone give a hint how to actually make an xib compatible to both the devices?

For more clarity I am adding screenshots:

When I set size 3.5 in attribute inspector: When I set size in attribute inspector to 3.5

it looks in iphone-5. There is a space below the buttons: And this is how it looks in simulator for 3.5 inch device

If I set size 4 inch in interface builder. You can see that bottom buttons are not visible in iphone-4. If I set size 3.5 inch in interface builder

So you will ask what are the settings I am using. Here are they:

enter image description here enter image description here enter image description here

14条回答
Anthone
2楼-- · 2020-01-25 14:01

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;
}
查看更多
家丑人穷心不美
3楼-- · 2020-01-25 14:01
  • In your storyboard, click 'Show file inspector'.
  • Under Interface builder document->Document versioning, select Deployment=iOS 5 (or your choice).

If this doesn't work, you need to work with each of your views. Select them. Under Attributes inspector for each of them, under View section, see Mode attribute. Set this to 'Redraw'.

If even that doesn't give satisfactory result, set the view size to the smallest of all the version you are going to use. And set the Mode attribute = 'Scale to fill'.

Programmatically, Mode attribute is view.contentmode property.

查看更多
登录 后发表回答