iOS字体拓展

作者: 笑颜_d1ed | 来源:发表于2021-10-11 17:34 被阅读0次
//
//  UIFont+Universal.swift
//  UIFont+Universal

import UIKit

extension UIFont {
    
    // MARK: - 字体
  
    
    static func lightSystemFont(ofSize size: CGFloat) -> UIFont {
        return .systemFont(ofSize: size, weight: UIFont.Weight.light)
    }
    
    static func regularSystemFont(ofSize size: CGFloat) -> UIFont {
        return .systemFont(ofSize: size, weight: UIFont.Weight.regular)
    }
    
    static func mediumSystemFont(ofSize size: CGFloat) -> UIFont {
        return .systemFont(ofSize: size, weight: UIFont.Weight.medium)
    }
    
    
    static func semiboldSystemFont(ofSize size: CGFloat) -> UIFont {
        return .systemFont(ofSize: size, weight: UIFont.Weight.semibold)
    }
    
    static func thinSystemFont(ofSize size: CGFloat) -> UIFont {
        return .systemFont(ofSize: size, weight: UIFont.Weight.thin)
    }
    
    
    static func ultraLightSystemFont(ofSize size: CGFloat) -> UIFont {
        return .systemFont(ofSize: size, weight: UIFont.Weight.light)
    }
    
    
    // MARK: - 平方字体
    ///苹方简体 - 常规体
    public static func pingfang(_ size: CGFloat) -> UIFont {
        return UIFont.init(name: "PingFangSC-Regular", size: size) ?? regularSystemFont(ofSize: size)
    }
    ///苹方简体 - 中黑体
    public static func pingfang(medium size: CGFloat) -> UIFont {
        return UIFont.init(name: "PingFangSC-Medium", size: size) ?? mediumSystemFont(ofSize: size)
    }
    ///苹方简体 - 中粗体
    public static func pingfang(bold size: CGFloat) -> UIFont {
        return UIFont(name: "PingFangSC-Semibold", size: size) ?? semiboldSystemFont(ofSize: size)
    }
    ///苹方简体 - 细体
    public static func pingfang(light size: CGFloat) -> UIFont {
        return UIFont(name: "PingFangSC-Light", size: size) ?? lightSystemFont(ofSize: size)
    }
    ///苹方简体 - 极细体
    public static func pingfang(ultralight size: CGFloat) -> UIFont {
        return UIFont.init(name: "PingFangSC-Ultralight", size: size) ?? ultraLightSystemFont(ofSize: size)
    }
    ///苹方简体 - 纤细体
    public static func pingfang(thin size: CGFloat) -> UIFont {
        return UIFont.init(name: "PingFangSC-Thin", size: size) ?? thinSystemFont(ofSize: size)
    }
    
    
}

相关文章

网友评论

    本文标题:iOS字体拓展

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