判断iPhone还是iPad设备

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了判断iPhone还是iPad设备相关的知识,希望对你有一定的参考价值。


1. 用[UIDevice currentDevice].model,这个返回的是一个NSString,你可以做如下判断就能知道设备是iPad还是iPhone.


if ([[UIDevice currentDevice].model rangeOfString:@"iPad"].location != NSNotFound) {
    NSLog(@"This is an iPad!");
}

2. 用UI_USER_INTERFACE_IDIOM()方法,这是系统定义的一条宏。使用方法也很简单。

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
    NSLog(@"This is an iPad!");
}
 
 
转自:http://blog.sina.com.cn/s/blog_3f88614f0100sdcm.html

以上是关于判断iPhone还是iPad设备的主要内容,如果未能解决你的问题,请参考以下文章