文字大小和按鈕看起來iPhone 7和iPhone 6不錯,但在iPhone 5S或iPhone上運行時,它們的大小保持相同的5字體大小和尺寸的UIView相同的iPhone 6和iPhone 5S,4S
如果我給出了15分的左側空間限制,它在iPhone 7上看起來非常好,但在iPhone 5上,這給出了太多的空間。
如何爲所有設備系列實現動態視圖和FontSize。
在此先感謝
文字大小和按鈕看起來iPhone 7和iPhone 6不錯,但在iPhone 5S或iPhone上運行時,它們的大小保持相同的5字體大小和尺寸的UIView相同的iPhone 6和iPhone 5S,4S
如果我給出了15分的左側空間限制,它在iPhone 7上看起來非常好,但在iPhone 5上,這給出了太多的空間。
如何爲所有設備系列實現動態視圖和FontSize。
在此先感謝
爲此您可以使用AutoLayout。只需將你的觀點限制在你的超級觀點邊緣。即
yourView -> superView.Leading.Margin
yourView -> superView.Trailing.Margin
使用視圖控制器的邊距,可以確保它在所有設備上都能正常工作。
對於字體大小 - Apple爲您提供了一種名爲'prefferedFontStyles'的東西,您幾乎可以在所有情況下使用它。所以,如果你希望你的按鍵,只是對所有設備的正常看文字大小,只要做到這一點:
yourLabel.font = UIFont.preferredBody
或
UIFont.preferredTitle
等等等等
希望幫助來獲得掛起它
如果,比方說,UIFont.systemFont(ofSize: 16)
在4.7英寸的iPhone(屏幕寬度爲375pt)上看起來不錯,但在較小的設備上太大,您可以嘗試縮放字體bas編輯屏幕寬度...
let fontSize = UIScreen.main.bounds.width/375 * 16
let font = UIFont.systemFont(ofSize: fontSize)
對於插圖,每@FlorensvonBuchwaldt,使用自動佈局來約束你的UILabel
到它的上海華盈的空間,然後設置layoutMargins
爲一個比例插圖...
let margin = UIScreen.main.bounds.width/375 * 15
myView.layoutMargins = UIEdgeInsets(top: margin, left: margin, bottom: margin, right: margin)
// create global width ratio constant and use it when your need
let _widthRatio : CGFloat = {
let ratio = _screenSize.width/375
return ratio
}()
//use constant
let font = UIFont.systemFont(ofSize: fontSize * _widthRatio)
// if you set font from storyboard then create subclass of your control
class YMWidthLabel: UILabel {
override func awakeFromNib() {
super.awakeFromNib()
font = font.withSize(font.pointSize * _widthRatio)
}
}
// Now bind YMWidthLabel class in storyboard
你可以展示你以前試過的東西,還有什麼沒有奏效?參見[問] –