Install Toast-Swift
masterYou can integrate Toast-Swift into your Xcode project using several dependency managers or by manual installation.
repository·master·Indexed 26 days ago
https://github.com/scalessec/toast-swiftA lightweight Swift extension that adds toast notifications to UIView objects. This native Swift port of the original Toast for iOS library allows for customizable durations, positions, titles, and images, with support for custom ToastStyle objects and global configuration via ToastManager.shared.
Toast-Swift extends UIView to allow triggering notifications with simple method calls. You can specify duration, position, titles, images, and tap completion handlers.
// basic usage
self.view.makeToast("This is a piece of toast")
// toast with a specific duration and position
self.view.makeToast("This is a piece of toast", duration: 3.0, position: .top)
// toast presented with multiple options and with a completion closure
self.view.makeToast("This is a piece of toast", duration: 2.0, point: CGPoint(x: 110.0, y: 110.0), title: "Toast Title", image: UIImage(named: "toast.png")) { didTap in
if didTap {
print("completion from tap")
} else {
print("completion without tap")
}
}
// display toast with an activity spinner
self.view.makeToastActivity(.center)
// display any view as toast
self.view.showToast(myView)
// immediately hides all toast views in self.view
self.view.hideAllToasts()You can create custom ToastStyle objects for specific toasts or configure the global ToastManager.shared to apply settings to all subsequent toasts.
// create a new style
var style = ToastStyle()
style.messageColor = .blue
// present the toast with the new style
self.view.makeToast("This is a piece of toast", duration: 3.0, position: .bottom, style: style)
// set the shared style for all toasts going forward
ToastManager.shared.style = style
self.view.makeToast("This is a piece of toast") // now uses the shared style
// toggle "tap to dismiss" functionality
ToastManager.shared.isTapToDismissEnabled = true
// toggle queueing behavior
ToastManager.shared.isQueueEnabled = trueEnsure your environment meets the requirements for the version you are using: