NSObject+CNLiveConfigModuleInline.swift 3.86 KB
//
//  CNLiveConfigModuleInline.swift
//  metaCode
//
//  Created by open on 2023/11/2.
//

import Foundation

///!!!: pragma mark - 检测是否是iPhoneX系列
/**判断是否是iPhone X系列*/
var isiPhoneXSeries: Bool {
    if #available(iOS 11, *) {
          guard let w = UIApplication.shared.delegate?.window, let unwrapedWindow = w else {
              return false
          }
          if unwrapedWindow.safeAreaInsets.left > 0 || unwrapedWindow.safeAreaInsets.bottom > 0 {
              print(unwrapedWindow.safeAreaInsets)
              return true
          }
    }
    return false
}

/**获取系统状态栏高度**/
var getSystemStatusBarHeight: CGFloat {
    return isiPhoneXSeries ? 44 : 20
}

/** 获取系统导航高度**/
var getSystemNavHeight: CGFloat {
    return isiPhoneXSeries ? (44+44) : 64
}

/**获取系统导航UI高度*/
var getSystemNavUiHeight: CGFloat {
    return get_system_nav_height() - get_system_statusBar_height()
}

/**获取系统tabbar高度*/
var getSystemTabbarHeight: CGFloat {
    return isiPhoneXSeries ? 83 : 49
}

/**获取系统tabbarUI高度*/
var getSystemTabbarUiHeight: CGFloat {
    return 49
}

/**获取系统tabbarUI增加的高度 (因iPhoneX系列底部有安全区域增加的高度)*/
var getSystemTabbarUiOffsetHeight: CGFloat {
    return get_system_tabbar_height() - get_system_tabbar_ui_height()
}

///!!!: #pragma mark - 字体

/**细体*/
func thin_font(pointSize: CGFloat) -> UIFont {
    if #available(iOS 8.2, *) {
        return UIFont.systemFont(ofSize: pointSize, weight: .thin)
    }else {
        return UIFont.systemFont(ofSize: pointSize)
    }
}

/**半细体*/
func light_font(pointSize: CGFloat) -> UIFont {
    if #available(iOS 8.2, *) {
        return UIFont.systemFont(ofSize: pointSize, weight: .light)
    }else {
        return UIFont.systemFont(ofSize: pointSize)
    }
}

/**正常体*/
func regular_font(pointSize: CGFloat) -> UIFont {
    if #available(iOS 8.2, *) {
        return UIFont.systemFont(ofSize: pointSize, weight: .regular)
    }else {
        return UIFont.systemFont(ofSize: pointSize)
    }
}

/**半粗体*/
func medium_font(pointSize: CGFloat) -> UIFont {
    if #available(iOS 8.2, *) {
        return UIFont.systemFont(ofSize: pointSize, weight: .medium)
    }else {
        return UIFont.systemFont(ofSize: pointSize)
    }
}

/**粗体*/
func semibold_font(pointSize: CGFloat) -> UIFont {
    if #available(iOS 8.2, *) {
        return UIFont.systemFont(ofSize: pointSize, weight: .semibold)
    }else {
        return UIFont.systemFont(ofSize: pointSize)
    }
}

///!!!: #pragma mark - 自适应字体

/**细体(自适应)*/
func thin_adapt_font(pointSize: CGFloat) -> UIFont {
    let multiple = UIScreen.main.bounds.size.width / 375
    let size = floor(pointSize*multiple)
    return thin_font(pointSize: size)
}

/**半细体(自适应)*/
func light_adapt_font(pointSize: CGFloat) -> UIFont {
    let multiple = UIScreen.main.bounds.size.width / 375
    let size = floor(pointSize*multiple)
    return light_font(pointSize: size)
}

/**正常体(自适应)*/
func regular_adapt_font(pointSize: CGFloat) -> UIFont {
    let multiple = UIScreen.main.bounds.size.width / 375
    let size = floor(pointSize*multiple)
    return regular_font(pointSize: size)
}

/**半粗体(自适应)*/
func medium_adapt_font(pointSize: CGFloat) -> UIFont {
    let multiple = UIScreen.main.bounds.size.width / 375
    let size = floor(pointSize*multiple)
    return medium_font(pointSize: size)
}

/**粗体(自适应)*/
func semibold_adapt_font(pointSize: CGFloat) -> UIFont {
    let multiple = UIScreen.main.bounds.size.width / 375
    let size = floor(pointSize*multiple)
    return semibold_font(pointSize: size)
}

///!!!: #pragma mark - 自适应长度
func adapt_length(length: CGFloat) -> CGFloat {
    let multiple = UIScreen.main.bounds.size.width / 375
    let f_adapt_length = floor(length * multiple)
    return f_adapt_length
}