为了屏幕适配的需要,有时候我们需要获得iOS设备的屏幕信息,然后根据该信息判断是哪一种iOS设备。
CGSize screenSize = [UIScreen mainScreen].bounds.size;
// 如果是iPhone
if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone) {
// 竖屏情况
if (screenSize.height > screenSize.width) {
if (screenSize.height == 568) {
NSLog(@"当前为iPhone 5/5c/5s iPod Touch5 设备");
}else if (screenSize.height == 667) {
NSLog(@"当前为iPhone6/6s设备");
}else if (screenSize.height == 736) {
NSLog(@"当前为iPhone6 Plus/iPhone6s Plus 设备");
}else {
NSLog(@"当前为iPhone4/4s 等其他设备");
}
}
// 横屏情况
if (screenSize.width > screenSize.height) {
if (screenSize.width == 568) {
NSLog(@"当前为iPhone 5/5c/5s iPod Touch5 设备");
}else if (screenSize.width == 667) {
NSLog(@"当前为iPhone6/6s设备");
}else if (screenSize.width == 736) {
NSLog(@"当前为iPhone6 Plus/iPhone6s Plus 设备");
}else {
NSLog(@"当前为iPhone4/4s 等其他设备");
}
}
}
网友评论