ios判断设备是iphone还是ipad

如题所述

  在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;
}
温馨提示:内容为网友见解,仅供参考
第1个回答  推荐于2016-06-04
您的意思应该是iOS开发中,如何判断接入设备是iPhone还是iPad吧
下面这行代码可以直接判断是否为手机,您的问题应该是需要不同的情况下加载不同的Xib吧
//判断手机
if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)

{
NSLog(@"iPhone");

}
else
{
NSLog(@"iPad");

}
第2个回答  2015-06-14
iPhone是手机 ipad是平板电脑大得多
相似回答