mirror of https://github.com/xaoxuu/ProHUD
支持设置tintColor
This commit is contained in:
parent
3ede7ea236
commit
5fb9e6efc3
|
@ -43,7 +43,7 @@ class CapsuleVC: ListVC {
|
||||||
Capsule(.info("一条简短的消息")).push()
|
Capsule(.info("一条简短的消息")).push()
|
||||||
}
|
}
|
||||||
section.add(title: "一条稍微长一点的消息") {
|
section.add(title: "一条稍微长一点的消息") {
|
||||||
Capsule(.info("一条稍微长一点的消息")).push()
|
Capsule(.systemError.title("500").message("一条稍微长一点的消息")).push()
|
||||||
}
|
}
|
||||||
section.add(title: "(默认)状态胶囊控件,用于状态显示,一个主程序窗口只有一个状态胶囊实例。") {
|
section.add(title: "(默认)状态胶囊控件,用于状态显示,一个主程序窗口只有一个状态胶囊实例。") {
|
||||||
Capsule(.info("状态胶囊控件,用于状态显示,一个主程序窗口只有一个状态胶囊实例。")).push()
|
Capsule(.info("状态胶囊控件,用于状态显示,一个主程序窗口只有一个状态胶囊实例。")).push()
|
||||||
|
@ -165,7 +165,7 @@ class CapsuleVC: ListVC {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extension Capsule.CapsuleViewModel {
|
extension Capsule.ViewModel {
|
||||||
|
|
||||||
static func info(_ text: String?) -> Self {
|
static func info(_ text: String?) -> Self {
|
||||||
.init()
|
.init()
|
||||||
|
@ -184,4 +184,14 @@ extension Capsule.CapsuleViewModel {
|
||||||
.duration(.infinity)
|
.duration(.infinity)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static var systemError: Self {
|
||||||
|
.init()
|
||||||
|
.icon(.init(systemName: "xmark.circle.fill"))
|
||||||
|
.tintColor(.systemRed)
|
||||||
|
}
|
||||||
|
static func systemError(_ text: String?) -> Self {
|
||||||
|
.systemError
|
||||||
|
.message(text)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
import UIKit
|
import UIKit
|
||||||
import ProHUD
|
import ProHUD
|
||||||
|
|
||||||
public extension ViewModel {
|
public extension BaseViewModel {
|
||||||
// static var plain: ViewModel {
|
// static var plain: ViewModel {
|
||||||
// ViewModel()
|
// ViewModel()
|
||||||
// }
|
// }
|
||||||
|
@ -16,27 +16,37 @@ public extension ViewModel {
|
||||||
// ViewModel(icon: UIImage(named: "prohud.note"))
|
// ViewModel(icon: UIImage(named: "prohud.note"))
|
||||||
// }
|
// }
|
||||||
// MARK: note
|
// MARK: note
|
||||||
static var note: ViewModel {
|
static var note: Self {
|
||||||
.init(icon: UIImage(named: "demo.note"))
|
.init()
|
||||||
|
.icon(.init(named: "demo.note"))
|
||||||
}
|
}
|
||||||
static func note(_ seconds: TimeInterval) -> ViewModel {
|
static func note(_ seconds: TimeInterval) -> Self {
|
||||||
.init(icon: UIImage(named: "demo.note"), duration: seconds)
|
.init()
|
||||||
|
.icon(.init(named: "demo.note"))
|
||||||
|
.duration(seconds)
|
||||||
}
|
}
|
||||||
static var msg: ViewModel {
|
static var msg: Self {
|
||||||
ViewModel(icon: UIImage(named: "demo.message"))
|
.init()
|
||||||
|
.icon(.init(named: "demo.message"))
|
||||||
}
|
}
|
||||||
static func msg(_ seconds: TimeInterval) -> ViewModel {
|
static func msg(_ seconds: TimeInterval) -> Self {
|
||||||
ViewModel(icon: UIImage(named: "demo.message"), duration: seconds)
|
.init()
|
||||||
|
.icon(.init(named: "demo.message"))
|
||||||
|
.duration(seconds)
|
||||||
}
|
}
|
||||||
static var delete: ViewModel {
|
static var delete: Self {
|
||||||
ViewModel(icon: UIImage(named: "demo.trash"))
|
.init()
|
||||||
|
.icon(.init(named: "demo.trash"))
|
||||||
}
|
}
|
||||||
// MARK: confirm
|
// MARK: confirm
|
||||||
static var confirm: ViewModel {
|
static var confirm: Self {
|
||||||
.init(icon: UIImage(named: "demo.questionmark"))
|
.init()
|
||||||
|
.icon(.init(named: "demo.questionmark"))
|
||||||
}
|
}
|
||||||
static func confirm(_ seconds: TimeInterval) -> ViewModel {
|
static func confirm(_ seconds: TimeInterval) -> Self {
|
||||||
.init(icon: UIImage(named: "demo.questionmark"), duration: seconds)
|
.init()
|
||||||
|
.icon(.init(named: "demo.questionmark"))
|
||||||
|
.duration(seconds)
|
||||||
}
|
}
|
||||||
|
|
||||||
// static func loading(_ seconds: TimeInterval) -> ViewModel {
|
// static func loading(_ seconds: TimeInterval) -> ViewModel {
|
||||||
|
|
|
@ -73,6 +73,8 @@ open class Alert: ProHUD.Controller {
|
||||||
return stack
|
return stack
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
open class ViewModel: BaseViewModel {}
|
||||||
|
|
||||||
/// 视图模型
|
/// 视图模型
|
||||||
public var vm = ViewModel()
|
public var vm = ViewModel()
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,7 @@ open class Capsule: Controller {
|
||||||
return lb
|
return lb
|
||||||
}()
|
}()
|
||||||
|
|
||||||
open class CapsuleViewModel: ViewModel {
|
open class ViewModel: BaseViewModel {
|
||||||
|
|
||||||
public enum Position {
|
public enum Position {
|
||||||
case top
|
case top
|
||||||
|
@ -72,11 +72,11 @@ open class Capsule: Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 视图模型
|
/// 视图模型
|
||||||
public var vm = CapsuleViewModel()
|
public var vm = ViewModel()
|
||||||
|
|
||||||
private var tapActionCallback: ((_ capsule: Capsule) -> Void)?
|
private var tapActionCallback: ((_ capsule: Capsule) -> Void)?
|
||||||
|
|
||||||
@discardableResult public init(_ vm: CapsuleViewModel, handler: ((_ capsule: Capsule) -> Void)? = nil) {
|
@discardableResult public init(_ vm: ViewModel, handler: ((_ capsule: Capsule) -> Void)? = nil) {
|
||||||
super.init()
|
super.init()
|
||||||
self.vm = vm
|
self.vm = vm
|
||||||
handler?(self)
|
handler?(self)
|
||||||
|
@ -97,7 +97,7 @@ open class Capsule: Controller {
|
||||||
|
|
||||||
public override func viewDidLoad() {
|
public override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
view.tintColor = config.tintColor
|
view.tintColor = vm.tintColor ?? config.tintColor
|
||||||
view.layer.shadowRadius = 8
|
view.layer.shadowRadius = 8
|
||||||
view.layer.shadowOffset = .init(width: 0, height: 5)
|
view.layer.shadowOffset = .init(width: 0, height: 5)
|
||||||
view.layer.shadowOpacity = 0.1
|
view.layer.shadowOpacity = 0.1
|
||||||
|
|
|
@ -33,7 +33,7 @@ extension Capsule: DefaultLayout {
|
||||||
|
|
||||||
// text
|
// text
|
||||||
textLabel.removeFromSuperview()
|
textLabel.removeFromSuperview()
|
||||||
let text = (vm.title ?? "") + (vm.message ?? "")
|
var text = [vm.title ?? "", vm.message ?? ""].filter({ $0.count > 0 }).joined(separator: " ")
|
||||||
if text.count > 0 {
|
if text.count > 0 {
|
||||||
contentStack.addArrangedSubview(textLabel)
|
contentStack.addArrangedSubview(textLabel)
|
||||||
textLabel.snp.makeConstraints { make in
|
textLabel.snp.makeConstraints { make in
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
//
|
//
|
||||||
// ViewModel.swift
|
// BaseViewModel.swift
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
// Created by xaoxuu on 2022/8/29.
|
// Created by xaoxuu on 2022/8/29.
|
||||||
//
|
//
|
||||||
|
@ -8,7 +8,7 @@
|
||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
/// 数据模型
|
/// 数据模型
|
||||||
open class ViewModel: NSObject {
|
open class BaseViewModel: NSObject {
|
||||||
|
|
||||||
/// 图标
|
/// 图标
|
||||||
open var icon: UIImage?
|
open var icon: UIImage?
|
||||||
|
@ -23,6 +23,8 @@ open class ViewModel: NSObject {
|
||||||
/// 消息正文
|
/// 消息正文
|
||||||
open var message: String?
|
open var message: String?
|
||||||
|
|
||||||
|
open var tintColor: UIColor?
|
||||||
|
|
||||||
/// 持续时间(为空代表根据场景不同的默认配置,为0代表无穷大)
|
/// 持续时间(为空代表根据场景不同的默认配置,为0代表无穷大)
|
||||||
open var duration: TimeInterval? {
|
open var duration: TimeInterval? {
|
||||||
didSet {
|
didSet {
|
||||||
|
@ -64,7 +66,7 @@ open class ViewModel: NSObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - convenience func
|
// MARK: - convenience func
|
||||||
public extension ViewModel {
|
public extension BaseViewModel {
|
||||||
|
|
||||||
func icon(_ image: UIImage?) -> Self {
|
func icon(_ image: UIImage?) -> Self {
|
||||||
self.icon = image
|
self.icon = image
|
||||||
|
@ -96,10 +98,15 @@ public extension ViewModel {
|
||||||
return self
|
return self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func tintColor(_ tintColor: UIColor?) -> Self {
|
||||||
|
self.tintColor = tintColor
|
||||||
|
return self
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - example scenes
|
// MARK: - example scenes
|
||||||
public extension ViewModel {
|
public extension BaseViewModel {
|
||||||
|
|
||||||
// MARK: plain
|
// MARK: plain
|
||||||
static func title(_ text: String?) -> Self {
|
static func title(_ text: String?) -> Self {
|
|
@ -36,7 +36,7 @@ public struct AppContext {
|
||||||
static var toastWindows: [UIWindowScene: [ToastWindow]] = [:]
|
static var toastWindows: [UIWindowScene: [ToastWindow]] = [:]
|
||||||
static var alertWindow: [UIWindowScene: AlertWindow] = [:]
|
static var alertWindow: [UIWindowScene: AlertWindow] = [:]
|
||||||
static var sheetWindows: [UIWindowScene: [SheetWindow]] = [:]
|
static var sheetWindows: [UIWindowScene: [SheetWindow]] = [:]
|
||||||
static var capsuleWindows: [UIWindowScene: [Capsule.CapsuleViewModel.Position: CapsuleWindow]] = [:]
|
static var capsuleWindows: [UIWindowScene: [Capsule.ViewModel.Position: CapsuleWindow]] = [:]
|
||||||
|
|
||||||
static var current: AppContext? {
|
static var current: AppContext? {
|
||||||
guard let windowScene = windowScene else { return nil }
|
guard let windowScene = windowScene else { return nil }
|
||||||
|
@ -120,7 +120,7 @@ extension AppContext {
|
||||||
var toastWindows: [ToastWindow] {
|
var toastWindows: [ToastWindow] {
|
||||||
Self.toastWindows[windowScene] ?? []
|
Self.toastWindows[windowScene] ?? []
|
||||||
}
|
}
|
||||||
var capsuleWindows: [Capsule.CapsuleViewModel.Position: CapsuleWindow] {
|
var capsuleWindows: [Capsule.ViewModel.Position: CapsuleWindow] {
|
||||||
Self.capsuleWindows[windowScene] ?? [:]
|
Self.capsuleWindows[windowScene] ?? [:]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,6 +83,8 @@ open class Toast: Controller {
|
||||||
/// 是否可以通过手势移除(向上滑出屏幕)
|
/// 是否可以通过手势移除(向上滑出屏幕)
|
||||||
public var isRemovable = true
|
public var isRemovable = true
|
||||||
|
|
||||||
|
open class ViewModel: BaseViewModel {}
|
||||||
|
|
||||||
/// 视图模型
|
/// 视图模型
|
||||||
public var vm = ViewModel()
|
public var vm = ViewModel()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue