import UIKit
import KeychainSwift
/// UDID
var USERUDID: String {
let key = "myUDID"
let keychina = KeychainSwift()
keychina.synchronizable = true
var sys_udid = keychina.get(key) // 得到存储的udid
if let sys_udid = sys_udid { // 有值
return sys_udid
}
// 没有值
sys_udid = UIDevice.current.identifierForVendor?.uuidString
if let sys_udid = sys_udid { // 有值
keychina.synchronizable = true
keychina.set(sys_udid, forKey: key)
return sys_udid
}
return ""
}
/// 屏宽
var KSCREEN_WIDTH: CGFloat {
return UIScreen.main.bounds.size.width
}
/// 屏高
var KSCREEN_HEIGHT: CGFloat {
return UIScreen.main.bounds.size.height
}
/// 状态栏高度
var KSTATUSBAR_HEIGHT: CGFloat {
let statusBarH: CGFloat = UIApplication.shared.statusBarFrame.size.height
if statusBarH > 0 {
return statusBarH
}else {
return isBangScreen ? 44.0 : 20.0
}
}
/// 导航条高度
var KNAVBAR_HEIGHT: CGFloat {
return 44.0
}
/// 状态栏+导航条高度
var KNAVBARANDSTATUSBAR_HEIGHT: CGFloat {
return KSTATUSBAR_HEIGHT + KNAVBAR_HEIGHT
}
/// tabbar高度
var KTABBAT_HEIGHT: CGFloat {
return isBangScreen ? 83.0 : 49.0
}
/// 底部高度 刘海屏: 34.0 非刘海屏: 0.0
var KBOTTOM_HEIGHT:CGFloat {
return isBangScreen ? 34.0 : 0.0
}
/// 是否为刘海屏 true: 刘海屏 false: 非刘海屏
var isBangScreen: Bool {
if #available(iOS 11, *) {
guard let w = UIApplication.shared.delegate?.window, let unwrapedWindow = w else { return false }
if unwrapedWindow.safeAreaInsets.bottom > 0 { return true }
}
return false
}
/// 日记打印
///
/// - Parameters:
/// - message: 打印的信息
/// - file: 文件名
/// - lineNumber: 行数
func LZYLogLine<T>(message: T, file: String = #file, lineNumber: Int = #line) {
#if DEBUG
let fileName = (file as NSString).lastPathComponent
print("[\(fileName):line:\(lineNumber)]---\(message)")
#endif
}
网友评论