在编程时可以通过下面语句判断设备,常量UIUserInterfaceIdiomPhone 用于判断是否为iPhone设备,UIUserInterfaceIdiomPad用于判断是否为iPad设备。
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
{
// iPhone设备
} else
{
// iPad 设备
}
typedef NS_ENUM(NSInteger, UIUserInterfaceIdiom) {
UIUserInterfaceIdiomUnspecified = -1,
#if __IPHONE_3_2 <= __IPHONE_OS_VERSION_MAX_ALLOWED
UIUserInterfaceIdiomPhone, // iPhone and iPod touch style UI
UIUserInterfaceIdiomPad, // iPad style UI
#endif
};
UIUserInterfaceIdiomUnspecified = -1,
#if __IPHONE_3_2 <= __IPHONE_OS_VERSION_MAX_ALLOWED
UIUserInterfaceIdiomPhone, // iPhone and iPod touch style UI
UIUserInterfaceIdiomPad, // iPad style UI
#endif
};