前端之家收集整理的这篇文章主要介绍了
swift -- 适配准备,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
public var DEVICE_TYPE:Int=0
public var DEVICE_WIDTH:CGFloat=0
public var DEVICE_HIGHT:CGFloat=0
public var FIT_RATE:CGFloat=1
func application(application: UIApplication,didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
let screenRect:CGRect=UIScreen.mainScreen().bounds
initDeviceInfo(screenRect)
return true
}
func initDeviceInfo(deviceRect:CGRect){
DEVICE_WIDTH=deviceRect.width
DEVICE_HIGHT=deviceRect.height
if DEVICE_HIGHT>=736{
DEVICE_TYPE=3
FIT_RATE=1.2
}else if DEVICE_HIGHT>=667 && DEVICE_HIGHT<736{
DEVICE_TYPE=2
FIT_RATE=1
}else if DEVICE_HIGHT>=568 && DEVICE_HIGHT<667{
DEVICE_TYPE=1
FIT_RATE=1
}else{
DEVICE_TYPE=0
FIT_RATE=0.8
}
}
class func getCurrentDeviceDpi()->CGFloat{
if DEVICE_TYPE==0{
return 3.78
}else if DEVICE_TYPE==1{
return 3.78
}else if DEVICE_TYPE==2{
return 3.17
}else if DEVICE_TYPE==3{
return 2.78
}else{
return 1.31
}
}
原文链接:https://www.f2er.com/swift/324261.html