简体   繁体   中英

Auto-resize iPhone xib app to ipad

I built an iPhone app "using xib" with 5-6 screens. Now I want to auto-resize the display for iPad. I am using xcode 4.6.

Do I have to rebuild the entire code using storyboards? It will be a very tedious work. Is there any solution for this?

You'll need to create only new xib files for iPad and name them as ViewController_iPhone.xib and ViewController_iPad.xib and when switching your views, just put a simple condition

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
    ViewController *viewController = [[ViewController alloc] initWithNibName:
                 @"ViewController_iPad" bundle:nil];
} else {
    ViewController *viewController = [[ViewController alloc] initWithNibName:
                 @"ViewController_iPhone" bundle:nil];
}

use autolayout and everything will be done automatically

在此输入图像描述

if not autolayout , then making 2 xib will be a better option. Make ipad size xib with the same name and put ~ipad after classname.

Like if you xib name is myClass.xib and create other one like myClass~ipad.xib .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM