Floating notification

The floating notification informs the user that an action has been taken. It can optionally include an icon and/or call-to-action (CTA) which may allow the user to view or undo the action.

Backpack/Floating Notification

Cocoapods class reference view on Github

Default

Day Night

Usage

Example of a Floating Notification:


                                                
                                                import Backpack
                                                
                                                final class ExampleViewController: UIViewController {
                                                    private lazy var exampleButton: BPKButton = {
                                                        let button = BPKButton(size: .default, style: .primary)
                                                        button.title = "Show"
                                                        button.addTarget(self, action: #selector(showNotificationTapped), for: .touchUpInside)
                                                        return button
                                                    }()
                                                
                                                    override func viewDidLoad() {
                                                        super.viewDidLoad()
                                                
                                                        view.addSubview(exampleButton)
                                                        exampleButton.translatesAutoresizingMaskIntoConstraints = false
                                                
                                                        NSLayoutConstraint.activate([
                                                            exampleButton.centerXAnchor.constraint(equalTo: view.centerXAnchor),
                                                            exampleButton.centerYAnchor.constraint(equalTo: view.centerYAnchor)
                                                        ])
                                                    }
                                                
                                                    @objc
                                                    private func showNotificationTapped() {
                                                        BPKFloatingNotification.show(.titleOnly(parentView: view, title: "Saved"))
                                                    }
                                                }

Example of a Floating Notification with icon and action:


                                                
                                                import Backpack
                                                
                                                final class ExampleViewController: UIViewController {
                                                    private lazy var exampleButton: BPKButton = {
                                                        let button = BPKButton(size: .default, style: .primary)
                                                        button.title = "Show"
                                                        button.addTarget(self, action: #selector(showNotificationTapped), for: .touchUpInside)
                                                        return button
                                                    }()
                                                
                                                    override func viewDidLoad() {
                                                        super.viewDidLoad()
                                                
                                                        view.addSubview(exampleButton)
                                                        exampleButton.translatesAutoresizingMaskIntoConstraints = false
                                                
                                                        NSLayoutConstraint.activate([
                                                            exampleButton.centerXAnchor.constraint(equalTo: view.centerXAnchor),
                                                            exampleButton.centerYAnchor.constraint(equalTo: view.centerYAnchor)
                                                        ])
                                                    }
                                                
                                                    @objc
                                                    private func showNotificationTapped() {
                                                        let action = { print("Tapped button") }
                                                
                                                        BPKFloatingNotification.show(            
                                                            .titleWithIconAndAction(
                                                                parentView: view,
                                                                title: "Saved",
                                                                iconName: .heart,
                                                                action: .action(title: "View", action: action)
                                                            )
                                                        )
                                                    }
                                                }