【iOS】判断苹果的设备是哪种

有时候需要判断苹果的设备是 iPhone 还是 iPad 等其他设备,示例代码如下:

if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
    NSLog(@"This is an iPad device"); //iPad 设备
} else if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
    NSLog(@"This is an iPhone device"); //iPhone 设备
}

 

官方 API 代码如下:

typedef NS_ENUM(NSInteger, UIUserInterfaceIdiom) {
    UIUserInterfaceIdiomUnspecified = -1,
    UIUserInterfaceIdiomPhone NS_ENUM_AVAILABLE_IOS(3_2), // iPhone and iPod touch style UI
    UIUserInterfaceIdiomPad NS_ENUM_AVAILABLE_IOS(3_2), // iPad style UI
};
posted @ 2016-03-17 19:27  WriteOnRead  阅读(310)  评论(0编辑  收藏  举报