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