在IOS3.2及以后的版本中, 可以使用UIKit中定义的函数UI_USER_INTERFACE_IDIOM来判断, 该函数返回两个值为UIUserInterfaceIdiomPhone和UIUserInterfaceIdiomPad.
为方便可在代码中定义isiPad来直接判断
|
1
|
#define isiPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
|
UI_USER_INTERFACE_IDIOM
Returns the interface idiom supported by the current device.
code 1234#define UI_USER_INTERFACE_IDIOM() \([[UIDevicecurrentDevice]respondsToSelector:@selector(userInterfaceIdiom)] ? \[[UIDevicecurrentDevice]userInterfaceIdiom] : \UIUserInterfaceIdiomPhone)
Return Value
UIUserInterfaceIdiomPhone if the device is an iPhone or iPod touch or UIUserInterfaceIdiomPad if the device is an iPad.
Availability
Available in iOS 3.2 and later.
Declared In
UIDevice.
转载:http://www.xw.hb.cn/Html/Article/iPhone/iPhone-iPad-check.html
本文介绍了如何使用UIKit中的UI_USER_INTERFACE_IDIOM函数判断iOS设备是iPhone还是iPad,提供了定义isiPad宏简化判断过程的方法,并解释了函数的返回值和可用性。
736

被折叠的 条评论
为什么被折叠?



