iOS 创建universal app

来源:互联网 发布:淘宝街拍用什么镜头 编辑:程序博客网 时间:2024/05/21 14:06

universal app supports both ipad and iphone。要了解universal如何支持both ipad and iphone,最直接的方法就是创建一个universal project。

universal project的基本特点:

1. target > summary > devices is universal


2. xib for ipad and xib for iphone can share the same view controller,当然使用不同的view controller绝对没问题。

3. in appdelegate.m didFinishLaunchingWithOptions method, use following code to 根据device是ipad还是iphone来指定 access 不同的 view

[cpp] view plaincopy
  1.     self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];  
  2.   
  3.     if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {  
  4.         self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPhone" bundle:nil];  
  5.     } else {  
  6.         self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPad" bundle:nil];  
  7.     }  
  8.   
  9. self.window.rootViewController = self.viewController; [self.window makeKeyAndVisible]; 

  10. 4. 其他class还可以通过[[UIDevice currentDevice] userInterfaceIdiom]来判断是ipad还是iphone来执行不同的代码非常简单,只需要把target > summary > devices option设置为universal即可。当然你要自己创建一组for ipad的ui,并在delegate.m里根据device指定不同的view。
原创粉丝点击