Optional step, you can use the default implementation: Toast
public struct MyToast: ToastType {
public var duration: ToastDuration
public var content: String
}
implement a ToastViewProviderType for your ToastType
public final class MyToastViewProvider: ToastViewProviderType<MyToast> {
@MainActor override public func viewForToast(toast: MyToast) -> UIView {
let view = UIView()
/*
....
Create a view and set it via the "toast" parameter.
This view will be displayed by toast center.
....
*/
return view
}
}
register your ToastViewProviderType into toast center
// If this type of toast is already registered, this will replace it.
ToastCenter.default.register(toastType: MyToast.self, with: MyToastViewProvider())
you can also customize the toast animation by implement your own ToastAnimatterType and set it to ToastCenter.default.toastAnimator replacing the default ToastAnimatter.
multiple scene support
ToastCenter.default display the toast view in the first UIWindowScene connected to the app.
you can create ToastCenter for diffrent window scenes by ToastCenter(windowScene: scene).
then using Toast(text:"toast text").show(in: center) to show toast.
🍞 Toaster
A toaster library for iOS written in Swift.
Feature
Screen record
https://user-images.githubusercontent.com/13523898/228002374-1222a236-1dc7-4c7d-b30b-6d82935a066d.MP4
Screenshot
Usage
install
To integrate Toaster into your Xcode project using Swift Package Manager, add it to the dependencies value of your Package.swift:
or using Xcode swift package manager:
using in code
How to customized
simple customize
full customize
implement you own ToastType
implement a ToastViewProviderType for your ToastType
register your ToastViewProviderType into toast center
show your toast
you can also customize the toast animation by implement your own ToastAnimatterType and set it to
ToastCenter.default.toastAnimator
replacing the default ToastAnimatter.multiple scene support
ToastCenter.default
display the toast view in the first UIWindowScene connected to the app.you can create ToastCenter for diffrent window scenes by
ToastCenter(windowScene: scene)
.then using
Toast(text:"toast text").show(in: center)
to show toast.