Files
yingmeng-ios-switf/yinmeng-ios/Base/Utils/Utils.swift

102 lines
3.2 KiB
Swift
Raw Normal View History

2024-02-21 21:30:13 +08:00
//
// Utils.swift
// yinmeng-ios
//
2024-03-05 14:04:09 +08:00
// Created by yinmeng on 2024/2/21.
2024-02-21 21:30:13 +08:00
//
import Foundation
2024-03-07 16:56:48 +08:00
2024-02-21 21:30:13 +08:00
let ScreenWidth = UIScreen.main.bounds.size.width
let ScreenHeight = UIScreen.main.bounds.size.height
2024-03-07 16:56:48 +08:00
let StatusBarHeight = UIDevice.yinStatusBarHeight()
let SafeAraeBottomHeight = UIDevice.yinSafeDistanceBottom()
let SafeAraeTopmHeight = UIDevice.yinSafeDistanceTop()
let NavHeight = UIDevice.yinNavigationFullHeight()
let TabHeight = UIDevice.yinTabBarHeight()
2024-03-05 14:04:09 +08:00
let keyWindow = UIApplication.shared.windows.first!
2024-02-24 13:49:51 +08:00
2024-03-07 16:56:48 +08:00
2024-02-24 13:49:51 +08:00
let DesKey = "1ea53d260ecf11e7b56e00163e046a26"
2024-02-26 23:04:17 +08:00
2024-03-28 19:56:25 +08:00
2024-03-07 16:56:48 +08:00
2024-03-22 11:54:23 +08:00
2024-03-07 16:56:48 +08:00
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()
}
}