From d0a50379a5d2afe5d6c9d93c61242ec877a58e70 Mon Sep 17 00:00:00 2001 From: Jerwin Pastoral Date: Mon, 19 May 2025 13:59:45 +0800 Subject: [PATCH] Add background color for toast parameter --- Sources/ToastSwift/ToastSwift.swift | 7 +++++-- Sources/ToastSwift/ToastView.swift | 5 ++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Sources/ToastSwift/ToastSwift.swift b/Sources/ToastSwift/ToastSwift.swift index 91cdaa6..37ad4c1 100644 --- a/Sources/ToastSwift/ToastSwift.swift +++ b/Sources/ToastSwift/ToastSwift.swift @@ -33,6 +33,7 @@ open class ToastSwift: Operation { @objc public var delay: TimeInterval = 0 @objc public var duration: TimeInterval = 2.0 + @objc public var action: (() -> Void)? private var _executing = false override public var isExecuting: Bool { @@ -63,17 +64,19 @@ open class ToastSwift: Operation { // MARK: Initializing @MainActor - @objc public init(text: String? = nil, willHideActionButton: Bool = true, delay: TimeInterval = 0, duration: TimeInterval = Delay.short) { + @objc public init(text: String? = nil, backgroundColor: UIColor = UIColor(red: 0.24, green: 0.24, blue: 0.24, alpha: 1.00), willHideActionButton: Bool = true, delay: TimeInterval = 0, duration: TimeInterval = Delay.short) { self.delay = delay self.duration = duration + self.view.backgroundColor = backgroundColor super.init() self.text = text } @MainActor - @objc public init(attributedText: NSAttributedString?, willHideActionButton: Bool = true, delay: TimeInterval = 0, duration: TimeInterval = Delay.short) { + @objc public init(attributedText: NSAttributedString?, backgroundColor: UIColor = UIColor(red: 0.24, green: 0.24, blue: 0.24, alpha: 1.00), willHideActionButton: Bool = true, delay: TimeInterval = 0, duration: TimeInterval = Delay.short) { self.delay = delay self.duration = duration + self.view.backgroundColor = backgroundColor super.init() self.attributedText = attributedText } diff --git a/Sources/ToastSwift/ToastView.swift b/Sources/ToastSwift/ToastView.swift index 6f2fae3..c295fba 100644 --- a/Sources/ToastSwift/ToastView.swift +++ b/Sources/ToastSwift/ToastView.swift @@ -113,7 +113,6 @@ open class ToastView: UIView { private lazy var backgroundView: UIView = { let `self` = UIView() - self.backgroundColor = UIColor(red: 0.24, green: 0.24, blue: 0.24, alpha: 1.00) self.layer.cornerRadius = 16 self.layer.masksToBounds = false self.layer.shadowPath = UIBezierPath(rect: self.bounds).cgPath @@ -126,7 +125,7 @@ open class ToastView: UIView { private lazy var textLabel: UILabel = { let `self` = UILabel() - self.textColor = .white + self.textColor = .black self.backgroundColor = .clear self.font = UIFont.systemFont(ofSize: 13.5) self.numberOfLines = 0 @@ -161,7 +160,7 @@ open class ToastView: UIView { self.addSubview(self.backgroundView) self.addSubview(self.columnStackView) self.columnStackView.addArrangedSubview(self.textLabel) - self.columnStackView.addArrangedSubview(self.actionTextLabel) +// self.columnStackView.addArrangedSubview(self.actionTextLabel) let actionLabelAttribute: [NSAttributedString.Key : Any] = [ NSAttributedString.Key.font: UIFont(name: "SFProDisplay-Medium", size: 13.5),