增加了 3 種新的寬度樣式:compressed、condensed與expanded,加上默認的standard,目前 UIFont 共有 4 種字體寬度。寬度大小關(guān)系為:expanded > standard > condensed > compressed。
// Created by YungFan
import UIKit
class ViewController: UIViewController {
// 定義4種寬度不同的字體
let expanded = UIFont.systemFont(ofSize: 27, weight: .bold, width: .expanded)
let standard = UIFont.systemFont(ofSize: 27, weight: .bold, width: .standard)
let condensed = UIFont.systemFont(ofSize: 27, weight: .bold, width: .condensed)
let compressed = UIFont.systemFont(ofSize: 27, weight: .bold, width: .compressed)
lazy var expandedLabel: UILabel = {
let label = UILabel(frame: CGRect(x: 10, y: 100, width: 360, height: 40))
label.text = "Xcode14 and iOS16"
label.font = expanded
return label
}()
lazy var standardLabel: UILabel = {
let label = UILabel(frame: CGRect(x: 10, y: 150, width: 360, height: 40))
label.text = "Xcode14 and iOS16"
label.font = standard
return label
}()
lazy var condensedLabel: UILabel = {
let label = UILabel(frame: CGRect(x: 10, y: 200, width: 360, height: 40))
label.text = "Xcode14 and iOS16"
label.font = condensed
return label
}()
lazy var compressedLabel: UILabel = {
let label = UILabel(frame: CGRect(x: 10, y: 250, width: 360, height: 40))
label.text = "Xcode14 and iOS16"
label.font = compressed
return label
}()
override func viewDidLoad() {
super.viewDidLoad()
view.addSubview(expandedLabel)
view.addSubview(standardLabel)
view.addSubview(condensedLabel)
view.addSubview(compressedLabel)
}
}