form1.cn
Make a little progress every day

Part 3:iOS 8多分辨率屏幕适配

04th of February 2017 Swift Swift 2210

在这一章中学习到多分辨率屏幕适配问题,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.
    }


}