102 lines
3.3 KiB
Swift
102 lines
3.3 KiB
Swift
//
|
||
// Utils.swift
|
||
// yinmeng-ios
|
||
//
|
||
// Created by yinmeng on 2024/2/21.
|
||
//
|
||
|
||
import Foundation
|
||
|
||
|
||
|
||
let ScreenWidth = UIScreen.main.bounds.size.width
|
||
let ScreenHeight = UIScreen.main.bounds.size.height
|
||
let StatusBarHeight = UIDevice.yinStatusBarHeight()
|
||
let SafeAraeBottomHeight = UIDevice.yinSafeDistanceBottom()
|
||
let SafeAraeTopmHeight = UIDevice.yinSafeDistanceTop()
|
||
let NavHeight = UIDevice.yinNavigationFullHeight()
|
||
let TabHeight = UIDevice.yinTabBarHeight()
|
||
let keyWindow = UIApplication.shared.windows.first!
|
||
|
||
|
||
let DesKey = "1ea53d260ecf11e7b56e00163e046a26"
|
||
|
||
let H5_URL = "http://beta.h5.ymlive.fun"
|
||
|
||
|
||
|
||
|
||
extension UIFont{
|
||
static func getScaleFont(ofSize:CGFloat,weight:Weight)->UIFont{
|
||
return UIFont.systemFont(ofSize: UIDevice.scaleWidth(width: ofSize), weight: weight)
|
||
}
|
||
}
|
||
extension UIDevice {
|
||
|
||
static func scaleWidth(width:CGFloat)->CGFloat{
|
||
return round(ScreenWidth / 375 * width)
|
||
}
|
||
static func scaleHeighth(width:CGFloat)->CGFloat{
|
||
return round(ScreenHeight / 812 * width)
|
||
}
|
||
/// 顶部安全区高度
|
||
static func yinSafeDistanceTop() -> CGFloat {
|
||
if #available(iOS 13.0, *) {
|
||
let scene = UIApplication.shared.connectedScenes.first
|
||
guard let windowScene = scene as? UIWindowScene else { return 0 }
|
||
guard let window = windowScene.windows.first else { return 0 }
|
||
return window.safeAreaInsets.top
|
||
}
|
||
guard let window = UIApplication.shared.windows.first else { return 0 }
|
||
return window.safeAreaInsets.top
|
||
|
||
}
|
||
|
||
/// 底部安全区高度
|
||
static func yinSafeDistanceBottom() -> CGFloat {
|
||
if #available(iOS 13.0, *) {
|
||
let scene = UIApplication.shared.connectedScenes.first
|
||
guard let windowScene = scene as? UIWindowScene else { return 0 }
|
||
guard let window = windowScene.windows.first else { return 0 }
|
||
return window.safeAreaInsets.bottom
|
||
}
|
||
guard let window = UIApplication.shared.windows.first else { return 0 }
|
||
return window.safeAreaInsets.bottom
|
||
|
||
}
|
||
|
||
/// 顶部状态栏高度(包括安全区)
|
||
static func yinStatusBarHeight() -> CGFloat {
|
||
var statusBarHeight: CGFloat = 0
|
||
if #available(iOS 13.0, *) {
|
||
let scene = UIApplication.shared.connectedScenes.first
|
||
guard let windowScene = scene as? UIWindowScene else { return 0 }
|
||
guard let statusBarManager = windowScene.statusBarManager else { return 0 }
|
||
statusBarHeight = statusBarManager.statusBarFrame.height
|
||
} else {
|
||
statusBarHeight = UIApplication.shared.statusBarFrame.height
|
||
}
|
||
return statusBarHeight
|
||
}
|
||
|
||
/// 导航栏高度
|
||
static func yinNavigationBarHeight() -> CGFloat {
|
||
return 44.0
|
||
}
|
||
|
||
/// 状态栏+导航栏的高度
|
||
static func yinNavigationFullHeight() -> CGFloat {
|
||
return UIDevice.yinStatusBarHeight() + UIDevice.yinNavigationBarHeight()
|
||
}
|
||
|
||
/// 底部导航栏高度
|
||
static func yinTabBarHeight() -> CGFloat {
|
||
return 49.0
|
||
}
|
||
|
||
/// 底部导航栏高度(包括安全区)
|
||
static func yinTabBarFullHeight() -> CGFloat {
|
||
return UIDevice.yinTabBarHeight() + UIDevice.yinSafeDistanceBottom()
|
||
}
|
||
}
|