- 在ios开发的过程中,有可能这里应用在iphone和ipad上都要使用,但是怎么判断当前设备是iphone还是ipad呢,在这里提供一种方法来判断这个设备是什么设备,具体代码如下
- ?
- NSString *nibTitle = @"PadContent"; //默认是ipad
- if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
- { //如果当前设备是iphone 就改为iphone的nib文件
- nibTitle = @"PhoneContent";
- }
- [[NSBundle mainBundle] loadNibNamed:nibTitle owner:self options:nil];//加载nib
- - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
- {
- self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
- // Override point for customization after application launch.
- if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
- self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController_iPhone"bundle:nil] autorelease];
- } else {
- self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController_iPad"bundle:nil] autorelease];
- }
- self.window.rootViewController = self.viewController;
- [self.window makeKeyAndVisible];
- return YES;
- }
判断是iphone还是ipad
最新推荐文章于 2018-12-19 17:32:47 发布