Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extended success and error hud's to support optional tint colour #219

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Demo/DemoViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
22 changes: 11 additions & 11 deletions PKHUD/HUD.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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):
Expand All @@ -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):
Expand Down
6 changes: 5 additions & 1 deletion PKHUD/PKHUDErrorView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 4 additions & 1 deletion PKHUD/PKHUDSuccessView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down