Easily display toast messages with optional icons, progress indicators, and blurred backgrounds in your iOS app.
- 🌟 Display simple toast messages or toasts with icons.
- 🔄 Optional progress indicator for toasts that represent a loading state.
- 🌌 Optional dark blurred background to overlay entire application.
- 📱 Support for both iOS and tvOS.
- 📍 Customizable toast display positions.
- Download the
ToastManager.swift
andToastView.swift
file from this repository. - Add it to your Xcode project.
- Basic Toast
Since
ToastManager
is a singleton, you do not instantiate it directly. Instead, you access the shared instance as follows:
let toastManager = ToastManager.shared
toastManager.showToast(
message: "Your message here",
image: UIImage(named: "your_image_name"),
isProgress: false,
position: .center,
duration: 2.0,
in: yourView,
withBackground: true)
- Toast with Icon
let image = UIImage(systemName: "star.fill")
toastManager.showToast(message: "Starred", image: image, position: .top)
- Toast with Progress Indicator
toastManager.showToast(message: "Loading...", isProgress: true, position: .bottom)
- Toast with Blurred Background Overlay
toastManager.showToast(message: "Blurred Background", position: .center, withBackground: true)
- Dismiss Toast Manually
toastManager.cancelCurrentToast()
- Dismiss Toast After a Delay
DispatchQueue.main.asyncAfter(deadline: .now() + 3.0) {
toastManager.cancelCurrentToast()
}
You can set the duration for which a toast should be displayed.
toastManager.showToast(message: "This will dismiss in 5 seconds", duration: 5.0)
Position the toast wherever you want using the ToastPosition enum.
- allowMultipleToasts: Set to true to allow showing multiple toasts at once.
- toastPadding: The spacing between multiple toasts, if enabled.
This guide should provide you with the basic usage of the ToastManager class to manage toast notifications in your app.
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.