ToasterPlus is a lightweight, customizable, and feature-rich Swift framework for displaying toast notifications in iOS applications. It supports various features like keyboard awareness, accessibility (VoiceOver), and multiple positioning options.
- Toast Notifications: Show simple, non-intrusive toast notifications anywhere in your app.
-
Customizable: Adjust colors, fonts, shadows, and more using
ToastAppearance
. - Positioning: Display toasts at the top, middle, or bottom of the screen with support for different alignments (e.g., left, center, right).
- Keyboard Awareness: Automatically adjusts toast position when the keyboard is shown or hidden.
- Accessibility: Supports VoiceOver for announcing toast messages.
- Predefined Styles: Use success, error, or warning presets out of the box.
- Queueing: Automatically queues multiple toasts for sequential display.
- In Xcode, go to
File
→Add Packages
. - Enter the repository URL:
https://github.com/ProkofievAndrii/ToasterPlus.git
. - Select the desired version and click "Add Package".
Add the following line to your Podfile
:
pod 'ToasterPlus'
Then run:
pod install
To display a basic toast notification:
Toast(message: "Hello, Toaster!")
You can save a Toast instance to a variable and cancel it if needed:
let toast = Toast(message: "Cancelable Toast")
toast.cancel()
To cancel the currently displayed toast:
ToastCenter.default.cancelCurrentToast()
To clear the entire toast queue:
ToastCenter.default.cancelAll()
To show a toast with custom styles using NSAttributedString:
let attributedText = NSAttributedString(
string: "Attributed Toast",
attributes: [
.foregroundColor: UIColor.red,
.backgroundColor: UIColor.yellow,
.font: UIFont.boldSystemFont(ofSize: 18),
.underlineStyle: NSUnderlineStyle.single.rawValue
]
)
Toast(attributedMessage: attributedText, position: .bottomCenter)
var appearance = ToastAppearance()
appearance.backgroundColor = .systemBlue
appearance.textColor = .white
appearance.cornerRadius = 8
appearance.font = .boldSystemFont(ofSize: 16)
Toast(message: "Custom Toast", appearance: appearance)
Toast.success(message: "Operation completed successfully!")
Toast.error(message: "Something went wrong!")
Toast.warning(message: "This is a warning!")
9 possible positions available
Toast(message: "Top Right Toast", position: .topRight)
Toast(message: "Middle Center Toast", position: .middleCenter)
Toast(message: "Bottom Left Toast", position: .bottomLeft)
Toasts automatically reposition themselves above the keyboard when it is shown. No additional configuration is needed.
To enable VoiceOver announcements for toasts:
ToastCenter.default.isSupportAccessibility = true
iOS 13.0+ Swift 5.0+
ToasterPlus is available under the MIT License.