答案 0 :(得分:1)
您可以使用尺寸等级。
答案 1 :(得分:0)
对于按钮,使用下面的代码
btn.titleLabel?.numberOfLines = 1
btn.titleLabel?.adjustsFontSizeToFitWidth = true
btn.titleLabel?.lineBreakMode = .byClipping
输出
答案 2 :(得分:0)
if UIScreen.mainScreen().bounds.size.height == 480 {
// iPhone 4
mybutton.titleLabel.font = mybutton.titleLabel.font.fontWithSize(20)
} else if UIScreen.mainScreen().bounds.size.height == 568 {
// IPhone 5
mybutton.titleLabel.fontt = mybutton.titleLabel.font.fontWithSize(20)
} else if UIScreen.mainScreen().bounds.size.width == 375 {
// iPhone 6
mybutton.titleLabel.font = mybutton.titleLabel.font.fontWithSize(20)
} else if UIScreen.mainScreen().bounds.size.width == 414 {
// iPhone 6+
mybutton.titleLabel.font = mybutton.titleLabel.font.fontWithSize(20)
} else if UIScreen.mainScreen().bounds.size.width == 768 {
// iPad
mybutton.titleLabel.font = mybutton.titleLabel.font.fontWithSize(20)
}
答案 3 :(得分:0)
我正在使用Device Pod来检查设备。 https://github.com/Ekhoo/Device 之后
switch Device.size() {
case .screen3_5Inch:
myButton.titleLabel?.font = UIFont(name: YourfontName, size: 20)
case .screen4Inch:
myButton.titleLabel?.font = UIFont(name: YourfontName, size: 22))
case .screen4_7Inch:
myButton.titleLabel?.font = UIFont(name: YourfontName, size: 23)
case .screen5_5Inch:
myButton.titleLabel?.font = UIFont(name: YourfontName, size: 25)
case .screen5_8Inch:
myButton.titleLabel?.font = UIFont(name: YourfontName, size: 28)
default:
print("Unknown size")
}