通用的:
优点:
一个安装包,方便管理、分发
可共用一套逻辑代码,数据结构建议:如果你的app,iPad版本跟iPhone版本的界面是差不多的,就做兼容iPad和iPhone的app,否则就分开做iPad版、iPhone版。
修改目标设备族(Build里面的Targeted Device Family选为iPhone/iPad ),如果未修改的话,在iPad上运行的话,还是iPhone界面,只不过能“2x”放大缩小,修改完target device之后,显示是iPad界面,原有iPhone上的界面效果在iPad只占屏幕一部分(ios 6以后发现,无论Target Device是否为Universal,运行什么device,显示该机器界面大小,至于显示效果是只占一部分还是超出屏幕,看代码怎么写的)
<span style="color: rgb(204, 0, 0); font-weight: bold; font-family: Arial, Helvetica, sans-serif; "> 适用条件:</span>
iPhone、iPad界面布局一样,比例相同,只不过大小不一样,直接在initWithFrame、initWithCorder里面做比例变换即可。
if(UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPad){//iPad 版本代码;}else{//iPhone/iPod touch 版本代码;}
2.关于资源文件: iOS Supports Device-Specific Resources(参考:官网中《Resource Programming Guide》iOS Supports Device-Specific Resources小节):格式如下:
<basename><device>.<filename_extension>device说明:一般都是:xxx~ipad.extension + xxx.extension俩套(不必xxx~iphone.extension)~ipad - The resource should be loaded on iPad devices only.
// 图片UIImage* anImage = [UIImage imageNamed:@"MyImage.png"];// On an iPhone or iPod touch device, the system loads the MyImage~iphone.png resource file, while on iPad, it loads the MyImage~ipad.png resource file. If a device-specific version of a resource is not found, the system falls back to looking for a resource with the original filename, which in the preceding example would be an image named MyImage.png// xibMyViewController *viewController = [[MyViewController alloc] initWithNibName:@"MyViewController" bundle:nil]// load MyViewController~ipad.xib on an iPad, and MyViewController.xib on other devices// 其他类似
@interface ViewController : UIViewController@end@interface ViewController_iPad : ViewController@end@interface ViewController_iPhone : ViewController@end适用条件: iPhone、iPad界面布局不一样,功能、流程、业务逻辑不一样
一个Universal程序还是iPhone、iPad俩个版本 ?
原文:http://www.cnblogs.com/lvyinbentengzhe/p/4192072.html