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

为了屏幕适配的需要,有时候我们需要获得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 等其他设备");
    }
}

}

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容