Files
yingmeng-ios-switf/yinmeng-ios/Base/Utils/Utils.swift
2024-03-22 11:54:23 +08:00

102 lines
3.3 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// 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()
}
}