增加了 3 种新的宽度样式:compressed
、condensed
与expanded
,加上默认的standard
,目前 UIFont 共有 4 种字体宽度。宽度大小关系为: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)
}
}
网友评论