iOS字体拓展

//
//  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)
    }
    
    
}

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容