判断用户的是iPhone还是iPad

在IOS3.2及以后的版本中, 可以使用UIKit中定义的函数UI_USER_INTERFACE_IDIOM来判断, 该函数返回两个值为UIUserInterfaceIdiomPhoneUIUserInterfaceIdiomPad.

为方便可在代码中定义isiPad来直接判断

#define isiPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)

 

 

UI_USER_INTERFACE_IDIOM

Returns the interface idiom supported by the current device.

#define UI_USER_INTERFACE_IDIOM() \
   ([[UIDevice currentDevice] respondsToSelector:@selector(userInterfaceIdiom)] ? \
   [[UIDevice currentDevice] 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.

 

 

XeonWell Studio