2019-07-31 17:40:39 +08:00
|
|
|
|
//
|
|
|
|
|
// HUDConfig.swift
|
|
|
|
|
// ProHUD
|
|
|
|
|
//
|
|
|
|
|
// Created by xaoxuu on 2019/7/29.
|
|
|
|
|
// Copyright © 2019 Titan Studio. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
|
|
2020-06-15 15:11:44 +08:00
|
|
|
|
@available(iOS 13.0, *)
|
|
|
|
|
public var sharedWindowScene: UIWindowScene?
|
|
|
|
|
|
2019-07-31 17:40:39 +08:00
|
|
|
|
public extension ProHUD {
|
|
|
|
|
struct Configuration {
|
|
|
|
|
|
2019-08-03 17:48:37 +08:00
|
|
|
|
/// 是否允许Debug模式输出
|
|
|
|
|
public var enableDebugPrint = true
|
|
|
|
|
|
2019-08-08 09:25:28 +08:00
|
|
|
|
/// 根控制器
|
|
|
|
|
public var rootViewController: UIViewController?
|
|
|
|
|
|
2020-06-15 15:11:44 +08:00
|
|
|
|
@available(iOS 13.0, *)
|
|
|
|
|
|
|
|
|
|
/// Xcode11 创建的基于 windowScene 的应用必须设置此值
|
|
|
|
|
public var windowScene: UIWindowScene? {
|
|
|
|
|
set {
|
|
|
|
|
sharedWindowScene = newValue
|
|
|
|
|
}
|
|
|
|
|
get {
|
|
|
|
|
return sharedWindowScene
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-03 17:48:37 +08:00
|
|
|
|
/// 动态颜色(适配iOS13)
|
|
|
|
|
public lazy var dynamicColor: UIColor = {
|
2020-06-15 15:11:44 +08:00
|
|
|
|
if #available(iOS 13.0, *) {
|
|
|
|
|
let color = UIColor { (traitCollection: UITraitCollection) -> UIColor in
|
|
|
|
|
if traitCollection.userInterfaceStyle == .dark {
|
|
|
|
|
return .init(white: 1, alpha: 1)
|
|
|
|
|
} else {
|
|
|
|
|
return .init(white: 0.1, alpha: 1)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return color
|
|
|
|
|
} else {
|
|
|
|
|
// Fallback on earlier versions
|
|
|
|
|
}
|
2019-08-12 15:02:36 +08:00
|
|
|
|
return .init(white: 0.1, alpha: 1)
|
2019-08-03 17:48:37 +08:00
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
/// 主标签文本颜色
|
|
|
|
|
public lazy var primaryLabelColor: UIColor = {
|
2019-08-08 09:25:28 +08:00
|
|
|
|
return dynamicColor.withAlphaComponent(0.8)
|
2019-08-03 17:48:37 +08:00
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
/// 次级标签文本颜色
|
|
|
|
|
public lazy var secondaryLabelColor: UIColor = {
|
2019-08-12 15:02:36 +08:00
|
|
|
|
return dynamicColor.withAlphaComponent(0.66)
|
2019-08-03 17:48:37 +08:00
|
|
|
|
}()
|
|
|
|
|
|
2019-08-12 15:02:36 +08:00
|
|
|
|
public func blurView(_ callback: @escaping () -> UIVisualEffectView) {
|
|
|
|
|
createBlurView = callback
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-03 17:48:37 +08:00
|
|
|
|
|
|
|
|
|
public var toast = Toast()
|
|
|
|
|
public var alert = Alert()
|
|
|
|
|
public var `guard` = Guard()
|
2019-07-31 17:40:39 +08:00
|
|
|
|
|
|
|
|
|
/// Toast的配置
|
|
|
|
|
/// - Parameter callback: 回调
|
|
|
|
|
public mutating func toast(_ callback: @escaping (inout Toast) -> Void) {
|
|
|
|
|
callback(&toast)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Alert的配置
|
|
|
|
|
/// - Parameter callback: 回调
|
|
|
|
|
public mutating func alert(_ callback: @escaping (inout Alert) -> Void) {
|
|
|
|
|
callback(&alert)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Guard的配置
|
|
|
|
|
/// - Parameter callback: 回调
|
|
|
|
|
public mutating func `guard`(_ callback: @escaping (inout Guard) -> Void) {
|
|
|
|
|
callback(&`guard`)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-05 20:13:17 +08:00
|
|
|
|
/// 配置
|
2019-08-03 17:48:37 +08:00
|
|
|
|
internal var cfg = ProHUD.Configuration()
|
|
|
|
|
|
|
|
|
|
public extension ProHUD {
|
|
|
|
|
static func config(_ config: (inout Configuration) -> Void) {
|
|
|
|
|
config(&cfg)
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-08-12 15:02:36 +08:00
|
|
|
|
|
|
|
|
|
internal var createBlurView: () -> UIVisualEffectView = {
|
|
|
|
|
return {
|
|
|
|
|
let vev = UIVisualEffectView()
|
|
|
|
|
if #available(iOS 13.0, *) {
|
2020-06-15 15:11:44 +08:00
|
|
|
|
vev.effect = UIBlurEffect(style: .systemMaterial)
|
2019-08-12 15:02:36 +08:00
|
|
|
|
} else if #available(iOS 11.0, *) {
|
|
|
|
|
vev.effect = UIBlurEffect(style: .extraLight)
|
|
|
|
|
} else {
|
|
|
|
|
vev.effect = .none
|
|
|
|
|
vev.backgroundColor = .white
|
|
|
|
|
}
|
|
|
|
|
return vev
|
|
|
|
|
}
|
|
|
|
|
}()
|