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

Custom Background Color and swipe up #11

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions CRNotifications/Classes/CRNotification.swift
Expand Up @@ -93,6 +93,9 @@ class CRNotification: UIView {
NotificationCenter.default.addObserver(self, selector: #selector(didRotate), name: NSNotification.Name.UIDeviceOrientationDidChange, object: nil)
let dismissRecognizer = UITapGestureRecognizer(target: self, action: #selector(self.dismissNotification))
addGestureRecognizer(dismissRecognizer)
let swipeRecognizer = UISwipeGestureRecognizer(target: self, action: #selector(self.dismissNotification))
swipeRecognizer.direction = .up
addGestureRecognizer(swipeRecognizer)
}

@objc func didRotate() {
Expand Down
12 changes: 8 additions & 4 deletions CRNotifications/Classes/CRNotifications.swift
Expand Up @@ -12,16 +12,20 @@ public class CRNotifications {

public init(){}

/// Shows a CRNotification
public static func showNotification(type: CRNotificationType, title: String, message: String, dismissDelay: TimeInterval, completion: @escaping () -> () = {}) {
/** Shows a CRNotification with a type, title, message, delay and completion callback */
public static func showNotification(type: CRNotificationType, title: String, message: String, dismissDelay: TimeInterval, completion: @escaping () -> () = {}) {
showNotification(type: type, title: title, message: message, dismissDelay: dismissDelay, backgroundColor: type.color, completion: completion)
}
/** Shows a CRNotification with a type, title, message, delay, background color and completion callback */
public static func showNotification(type: CRNotificationType, title: String, message: String, dismissDelay: TimeInterval, backgroundColor: UIColor, completion: @escaping () -> () = {}) {
let view = CRNotification()

view.setBackgroundColor(color: type.color)
view.setBackgroundColor(color: backgroundColor)
view.setImage(image: type.image)
view.setTitle(title: title)
view.setMessage(message: message)
view.setDismisTimer(delay: dismissDelay)
view.setCompletionBlock(completion)
view.setCompletionBlock(completion)

guard let window = UIApplication.shared.keyWindow else {
print("Failed to show CRNotification. No keywindow available.")
Expand Down