根据屏幕分辨率判断当前手机型号(swift4.1)

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        
        var label = "1"
        
        //获取屏幕大小
        let iOSDeviceScreenSize: CGSize = UIScreen.main.bounds.size
        
        NSLog("%@ x %@", iOSDeviceScreenSize.width, iOSDeviceScreenSize.height)
        var s : NSString = NSString(format: "%@ x %@",iOSDeviceScreenSize.width,iOSDeviceScreenSize.height)
        label = s as String
        
        
        //获取设备信息,判断是否为iphone
        if (UIDevice.current.userInterfaceIdiom == UIUserInterfaceIdiom.phone) {

            //判断是否为竖屏
            if (iOSDeviceScreenSize.height > iOSDeviceScreenSize.width){
                if(iOSDeviceScreenSize.height == 568){
                    NSLog("iphone5/5s/5c/se")
                } else if (iOSDeviceScreenSize.height == 667){
                    NSLog("iphone 6/6s/7/8")
                } else if (iOSDeviceScreenSize.height == 736){
                    NSLog("iphone 6plus/6Splus/7plus/8plus ")
                } else if (iOSDeviceScreenSize.height == 812){
                    NSLog("iphone X/XS ")
                } else if (iOSDeviceScreenSize.height == 896){
                    NSLog("iphone XR/XSMax ")
                } else {
                    NSLog("iphone4s....")
                }
            }
            
            if (iOSDeviceScreenSize.width > iOSDeviceScreenSize.height){
                if(iOSDeviceScreenSize.width == 568){
                    NSLog("iphone5/5s/5c/se")
                } else if (iOSDeviceScreenSize.width == 667){
                    NSLog("iphone 6/6s/7/8")
                } else if (iOSDeviceScreenSize.width == 736){
                    NSLog("iphone 6plus/6Splus/7plus/8plus ")
                } else if (iOSDeviceScreenSize.width == 812){
                    NSLog("iphone X/XS ")
                } else if (iOSDeviceScreenSize.width == 896){
                    NSLog("iphone XR/XSMax ")
                } else {
                    NSLog("iphone4s....")
                }
            }
            
        }
        
        
        
        
    }


}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值