iOS 常用拓展

iOS字体拓展

2021-10-11  本文已影响0人  笑颜_d1ed
//
//  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)
    }
    
    
}

上一篇下一篇

猜你喜欢

热点阅读