77 lines
2.8 KiB
Swift
77 lines
2.8 KiB
Swift
//
|
|
// SPDefine.swift
|
|
// ShortPlay
|
|
//
|
|
// Created by 曾觉新 on 2025/4/8.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
//MARK:-------------- 屏幕尺寸相关 --------------
|
|
let kSPScreenWidth = UIScreen.main.bounds.size.width
|
|
let kSPScreenHeight = UIScreen.main.bounds.size.height
|
|
let kSPNavBarHeight : CGFloat = ((kSPStatusbarHeight != 59) ? kSPStatusbarHeight: 54) + 44 // 灵动岛
|
|
let kSPTabBarHeight : CGFloat = kSPTabbarSafeBottomMargin + 49
|
|
|
|
///状态栏高度
|
|
let kSPStatusbarHeight: CGFloat = {
|
|
var top: CGFloat = 20
|
|
if #available(iOS 11.0, *) {
|
|
top = UIApplication.shared.windows[0].safeAreaInsets.top
|
|
top = (top != 59) ? top : 54 //灵动岛
|
|
top = top == 0 ? 20 : top
|
|
}
|
|
return top
|
|
}()
|
|
///tab高度
|
|
let kSPTabbarSafeBottomMargin: CGFloat = {
|
|
var bottom: CGFloat = 0
|
|
if #available(iOS 11.0, *) {
|
|
bottom = UIApplication.shared.windows[0].safeAreaInsets.bottom
|
|
}
|
|
return bottom
|
|
}()
|
|
|
|
// 从375自适应
|
|
public let kSPMainW:((CGFloat)-> CGFloat) = { (size : CGFloat) -> CGFloat in
|
|
return kSPWidthScale * size
|
|
}
|
|
///宽比
|
|
let kSPWidthScale = kSPScreenWidth / 375
|
|
|
|
//MARK:-------------- 系统版本号 --------------
|
|
///当前系统版本号
|
|
let kSP_osVersion: String = UIDevice.current.systemVersion
|
|
let kSPAPPBundleIdentifier: String = (Bundle.main.infoDictionary!["CFBundleIdentifier"] as? String) ?? "0"
|
|
|
|
///app版本号
|
|
public let kSPAPPVersion: String = (Bundle.main.infoDictionary!["CFBundleShortVersionString"] as? String) ?? "0"
|
|
public let kSPAPPBundleVersion: String = (Bundle.main.infoDictionary!["CFBundleVersion"] as? String) ?? "0"
|
|
|
|
public let kSPAPPBundleName: String = (Bundle.main.infoDictionary!["CFBundleName"] as? String) ?? ""
|
|
|
|
//MARK: ------- 打印信息 ----------
|
|
public func spLog(message:Any? , file: String = #file, function: String = #function, line: Int = #line) {
|
|
#if DEBUG
|
|
print("\n\(Date(timeIntervalSinceNow: 8 * 60 * 60)) \(file.components(separatedBy: "/").last ?? "") \(function) \(line): \(message ?? "")")
|
|
#endif
|
|
}
|
|
|
|
|
|
public func sp_swizzled_instanceMethod(_ prefix: String, oldClass: Swift.AnyClass!, oldSelector: String, newClass: Swift.AnyClass) {
|
|
let newSelector = prefix + "_" + oldSelector;
|
|
let originalSelector = NSSelectorFromString(oldSelector)
|
|
let swizzledSelector = NSSelectorFromString(newSelector)
|
|
|
|
let originalMethod = class_getInstanceMethod(oldClass, originalSelector)
|
|
let swizzledMethod = class_getInstanceMethod(newClass, swizzledSelector)
|
|
|
|
let isAdd = class_addMethod(oldClass, originalSelector, method_getImplementation(swizzledMethod!), method_getTypeEncoding(swizzledMethod!))
|
|
|
|
if isAdd {
|
|
class_replaceMethod(newClass, swizzledSelector, method_getImplementation(originalMethod!), method_getTypeEncoding(originalMethod!))
|
|
}else {
|
|
method_exchangeImplementations(originalMethod!, swizzledMethod!)
|
|
}
|
|
}
|