美文网首页iOS16适配指南
iOS16适配指南之UIFont

iOS16适配指南之UIFont

作者: YungFan | 来源:发表于2022-09-09 15:14 被阅读0次

    增加了 3 种新的宽度样式:compressedcondensedexpanded,加上默认的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)
        }
    }

    相关文章

      网友评论

        本文标题:iOS16适配指南之UIFont

        本文链接:https://www.haomeiwen.com/subject/antznrtx.html