| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- //
- // UIFont+Extension.swift
- // QuickSearchLocation
- //
- // Created by mac on 2024/4/10.
- //
- import UIKit
- // MARK: - 常用的系统基本字体扩展
- extension UIFont {
-
- // MARK: 1.1、默认字体
- /// 默认字体
- /// - Parameter ofSize: 字体大小
- /// - Returns: 字体
- static func textF(_ ofSize: CGFloat) -> UIFont {
- return text(ofSize, W: .regular)
- }
-
- // MARK: 1.2、常规字体
- /// 常规字体
- /// - Parameter ofSize: 字体大小
- /// - Returns: 字体
- static func textR(_ ofSize: CGFloat) -> UIFont {
- return text(ofSize, W: .regular)
- }
-
- // MARK: 1.3、中等的字体
- /// - Parameter ofSize: 字体大小
- /// - Returns: 字体
- static func textM(_ ofSize: CGFloat) -> UIFont {
- return text(ofSize, W: .medium)
- }
-
- // MARK: 1.4、加粗的字体
- /// 加粗的字体
- /// - Parameter ofSize: 字体大小
- /// - Returns: 字体
- static func textB(_ ofSize: CGFloat) -> UIFont {
- return text(ofSize, W: .bold)
- }
-
- // MARK: 1.5、半粗体的字体
- /// 半粗体的字体
- /// - Parameter ofSize: 字体大小
- /// - Returns: 字体
- static func textSB(_ ofSize: CGFloat) -> UIFont {
- return text(ofSize, W: .semibold)
- }
-
- // MARK: 1.6、超细的字体
- /// 超细的字体
- /// - Parameter ofSize: 字体大小
- /// - Returns: 字体
- static func textUltraLight(_ ofSize: CGFloat) -> UIFont {
- return text(ofSize, W: .ultraLight)
- }
-
- // MARK: 1.7、纤细的字体
- /// 纤细的字体
- /// - Parameter ofSize: 字体大小
- /// - Returns: 字体
- static func textThin(_ ofSize: CGFloat) -> UIFont {
- return text(ofSize, W: .thin)
- }
-
- // MARK: 1.8、亮字体
- /// 亮字体
- /// - Parameter ofSize: 字体大小
- /// - Returns: 字体
- static func textLight(_ ofSize: CGFloat) -> UIFont {
- return text(ofSize, W: .light)
- }
-
- // MARK: 1.9、介于Bold和Black之间
- /// 介于Bold和Black之间
- /// - Parameter ofSize: 字体大小
- /// - Returns: 字体
- static func textHeavy(_ ofSize: CGFloat) -> UIFont {
- return text(ofSize, W: .heavy)
- }
-
- // MARK: 1.10、最粗字体
- /// 最粗字体
- /// - Parameter ofSize: 字体大小
- /// - Returns: 字体
- static func textBlack(_ ofSize: CGFloat) -> UIFont {
- return text(ofSize, W: .black)
- }
-
- /// 文字字体
- fileprivate static func text(_ ofSize: CGFloat, W Weight: UIFont.Weight) -> UIFont {
- let scaleSize = ofSize.rpx
- return UIFont.systemFont(ofSize: scaleSize, weight: Weight)
- }
-
- func withTraits(traits: UIFontDescriptor.SymbolicTraits) -> UIFont {
- let descriptor = fontDescriptor.withSymbolicTraits(traits)
- return UIFont(descriptor: descriptor!, size: 0)
- }
- }
|