Hien,
這是關於檢測設備/屏幕尺寸的超級貼子。
How to detect iPhone 5 (widescreen devices)?
這是上我最喜歡的建議,請點擊它,並感謝真正的作者!
添加一個 '新雨燕文件' - > AppDelegateEx.swift
添加擴展的appdelegate
import UIKit
extension AppDelegate {
class func isIPhone5() -> Bool{
return max(UIScreen.mainScreen().bounds.width, UIScreen.mainScreen().bounds.height) == 568.0
}
class func isIPhone6() -> Bool {
return max(UIScreen.mainScreen().bounds.width, UIScreen.mainScreen().bounds.height) == 667.0
}
class func isIPhone6Plus() -> Bool {
return max(UIScreen.mainScreen().bounds.width, UIScreen.mainScreen().bounds.height) == 736.0
}
}
用法:
if AppDelegate.isIPhone5() {
collectionViewTopConstraint.constant = 2
}else if AppDelegate.isIPhone6() {
collectionViewTopConstraint.constant = 20
}
與應用程序中設置字體結合起來,你現在肯定應該做的?
variable.font = UIFont(name: "Palatino", size: 24)
檢測屏幕寬度,然後手動設置字體。 [http://stackoverflow.com/questions/25780283/ios-how-to-detect-iphone-6-plus-iphone-6-iphone-5-by-macro](http://stackoverflow.com/questions/ 25780283/ios-how-to-detect-iphone-6-plus-iphone-6-iphone-5-by-macro) –