diff --git a/Demo/DemoViewController.swift b/Demo/DemoViewController.swift index 7ce1a08..0755685 100644 --- a/Demo/DemoViewController.swift +++ b/Demo/DemoViewController.swift @@ -19,11 +19,12 @@ class DemoViewController: UIViewController { } @IBAction func showAnimatedSuccessHUD(_ sender: AnyObject) { - HUD.flash(.success, delay: 2.0) + HUD.flash(.success, tintColor: UIColor.orange, delay: 2.0) } @IBAction func showAnimatedErrorHUD(_ sender: AnyObject) { - HUD.show(.error) + // Error with optional tint color + HUD.show(.error,tintColor: UIColor.red) HUD.hide(afterDelay: 2.0) } diff --git a/PKHUD/HUD.swift b/PKHUD/HUD.swift index 5e4b853..f390d3e 100644 --- a/PKHUD/HUD.swift +++ b/PKHUD/HUD.swift @@ -42,8 +42,8 @@ public final class HUD { public static var isVisible: Bool { return PKHUD.sharedHUD.isVisible } // MARK: Public methods, PKHUD based - public static func show(_ content: HUDContentType, onView view: UIView? = nil) { - PKHUD.sharedHUD.contentView = contentView(content) + public static func show(_ content: HUDContentType, tintColor:UIColor? = nil, onView view: UIView? = nil) { + PKHUD.sharedHUD.contentView = contentView(content, tintColor: tintColor) PKHUD.sharedHUD.show(onView: view) } @@ -60,23 +60,23 @@ public final class HUD { } // MARK: Public methods, HUD based - public static func flash(_ content: HUDContentType, onView view: UIView? = nil) { - HUD.show(content, onView: view) + public static func flash(_ content: HUDContentType, tintColor:UIColor? = nil, onView view: UIView? = nil) { + HUD.show(content, tintColor: tintColor, onView: view) HUD.hide(animated: true, completion: nil) } - public static func flash(_ content: HUDContentType, onView view: UIView? = nil, delay: TimeInterval, completion: ((Bool) -> Void)? = nil) { - HUD.show(content, onView: view) + public static func flash(_ content: HUDContentType, tintColor:UIColor? = nil, onView view: UIView? = nil, delay: TimeInterval, completion: ((Bool) -> Void)? = nil) { + HUD.show(content, tintColor: tintColor, onView: view) HUD.hide(afterDelay: delay, completion: completion) } // MARK: Private methods - fileprivate static func contentView(_ content: HUDContentType) -> UIView { + fileprivate static func contentView(_ content: HUDContentType, tintColor:UIColor? = nil) -> UIView { switch content { case .success: - return PKHUDSuccessView() + return PKHUDSuccessView(tintColor: tintColor) case .error: - return PKHUDErrorView() + return PKHUDErrorView(tintColor: tintColor) case .progress: return PKHUDProgressView() case let .image(image): @@ -85,9 +85,9 @@ public final class HUD { return PKHUDRotatingImageView(image: image) case let .labeledSuccess(title, subtitle): - return PKHUDSuccessView(title: title, subtitle: subtitle) + return PKHUDSuccessView(title: title, subtitle: subtitle, tintColor: tintColor) case let .labeledError(title, subtitle): - return PKHUDErrorView(title: title, subtitle: subtitle) + return PKHUDErrorView(title: title, subtitle: subtitle, tintColor:tintColor) case let .labeledProgress(title, subtitle): return PKHUDProgressView(title: title, subtitle: subtitle) case let .labeledImage(image, title, subtitle): diff --git a/PKHUD/PKHUDErrorView.swift b/PKHUD/PKHUDErrorView.swift index 6c60d5d..92d1f53 100644 --- a/PKHUD/PKHUDErrorView.swift +++ b/PKHUD/PKHUDErrorView.swift @@ -33,12 +33,16 @@ open class PKHUDErrorView: PKHUDSquareBaseView, PKHUDAnimating { return dash } - public init(title: String? = nil, subtitle: String? = nil) { + public init(title: String? = nil, subtitle: String? = nil, tintColor:UIColor? = nil) { super.init(title: title, subtitle: subtitle) layer.addSublayer(dashOneLayer) layer.addSublayer(dashTwoLayer) dashOneLayer.position = layer.position dashTwoLayer.position = layer.position + if let tintColor = tintColor{ + dashOneLayer.strokeColor = tintColor.cgColor + dashTwoLayer.strokeColor = tintColor.cgColor + } } public required init?(coder aDecoder: NSCoder) { diff --git a/PKHUD/PKHUDSuccessView.swift b/PKHUD/PKHUDSuccessView.swift index adbe3e7..2c2187a 100644 --- a/PKHUD/PKHUDSuccessView.swift +++ b/PKHUD/PKHUDSuccessView.swift @@ -30,9 +30,12 @@ open class PKHUDSuccessView: PKHUDSquareBaseView, PKHUDAnimating { return layer }() - public init(title: String? = nil, subtitle: String? = nil) { + public init(title: String? = nil, subtitle: String? = nil, tintColor:UIColor? = nil) { super.init(title: title, subtitle: subtitle) layer.addSublayer(checkmarkShapeLayer) + if let tintColor = tintColor{ + checkmarkShapeLayer.strokeColor = tintColor.cgColor + } checkmarkShapeLayer.position = layer.position }