iOS Swift 多分辨率屏幕适配

学习到多分辨率屏幕适配问题,ScrollView、assets.xcassets 的初步认识

import UIKit
 
class ViewController: UIViewController {
 
    @IBOutlet weak var label: UILabel!
     
    @IBOutlet weak var ScrollView: UIScrollView!
     
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
         
        let iosDeviceScreenSize: CGSize = UIScreen.main.bounds.size//初始化关于设备的结构体
         
        let deviceWidth = iosDeviceScreenSize.width//设备的宽,单位(点)pt
        let deviceHeight = iosDeviceScreenSize.height//设备的高,单位(点)pt
        let deviceName = UIDevice.current.name  //获取设备名称 例如:梓辰的手机
        let sysName = UIDevice.current.systemName //获取系统名称 例如:iPhone OS
        let sysVersion = UIDevice.current.systemVersion //获取系统版本 例如:9.2
        let deviceUUID = UIDevice.current.identifierForVendor?.uuidString//获取设备唯一标识符 例如:FBF2306E-A0D8-4F4B-BDED-9333B627D3E6
        let deviceModel = UIDevice.current.model //获取设备的型号 例如:iPhone
         
        print("\(deviceName) - \(sysName) - \(sysVersion) - \(deviceModel) - \(deviceUUID) - ")
        print("\(deviceWidth) - \(deviceHeight)")
         
        if deviceModel == "iPhone" {//是否iphone设备
            self.label.text = "iphone设备"
             
            if deviceWidth == 568 || deviceHeight == 568 {
                self.label.text = "iphone设备 - iphone 5"
            } else if deviceWidth == 667 || deviceHeight == 667 {
                self.label.text = "iphone设备 - iphone 6...7"
            } else if deviceWidth == 736 || deviceHeight == 736  {
                self.label.text = "iphone设备 - iphone 6...7 Plus"
            } else {
                self.label.text = "iphone设备 - iphone 4"
            }
             
        } else {//否则pad设备
            self.label.text = "pad设备"
             
        }
         
    }
     
    override func viewDidLayoutSubviews() {
        self.ScrollView.contentSize = CGSize.init(width: self.view.frame.size.width, height: 1000)
        //设置scrollView的CG(滚动的)宽和高
    }
 
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
 
 
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

编程工人

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值