您的位置:首页 > 移动开发 > IOS开发

iOS根据屏幕宽高判断当前设备型号

2015-10-22 15:37 483 查看
为了屏幕适配的需要,有时候我们需要获得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 等其他设备");
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: