A lightweight, customizable SwiftUI toast notification library for iOS and macOS.
- EasyToast
- Simple Text Toasts: Display a quick message to the user with just a few lines of code.
- Flexible Positioning: Position the toast at the top, center, or bottom of the screen.
- Configurable Duration: Control how long the toast remains visible.
- Customizable Appearance: Background color, text color, corner radius, font, padding, shadow, and text alignment.
- Predefined Toast Types: Use built-in styles like
.success
,.error
,.warning
, and.info
. - Interactive Toasts: Add custom behavior when the toast is tapped.
- Custom Toast Views: Display fully custom-designed toast notifications.
- Item-based Toasts: Show a toast for any optional item, with a custom view for each value.
- Swift Package Manager Support: Easy integration into your project.
EasyToast is designed for SwiftUI developers who want a simple, flexible, and modern way to show toast notifications. It supports both quick messages and fully custom views, with smooth animations and easy configuration.
Add EasyToast to your project:
.package(url: "https://github.com/banghuazhao/EasyToast.git", from: "0.5.0")
Or use Xcode:
File > Add Packages...
and enter the repo URL.
import EasyToast
struct ContentView: View {
@State private var showToast = false
var body: some View {
VStack {
Button("Show Toast") { showToast = true }
}
.toast(isPresented: $showToast, message: "Hello, EasyToast!")
}
}
.toast(isPresented: $showToast, message: "This is a toast message!")
.toast(isPresented: $showToast, message: "On Top", position: .top)
.toast(
isPresented: $showToast,
message: "Custom Style",
style: ToastStyle(backgroundColor: .blue, textColor: .white)
)
.toast(isPresented: $showToast, message: "Success!", type: .success)
@State var selectedToast: String? = nil
Button("Show Custom Toast") { selectedToast = "Custom Toast!" }
.toast(item: $selectedToast) { value in
HStack {
Image(systemName: "checkmark.circle").foregroundColor(.white)
Text(value).foregroundColor(.white)
}
.padding()
.background(Color.green)
.cornerRadius(20)
}
Gradient Toast:
.toast(item: $selectedGradientToast) { value in
HStack {
Image(systemName: "flame.fill").foregroundColor(.white)
Text(value).foregroundColor(.white)
}
.padding()
.background(
LinearGradient(
gradient: Gradient(colors: [.purple, .blue]),
startPoint: .leading,
endPoint: .trailing
)
)
.cornerRadius(20)
}
Toast with Action:
.toast(item: $selectedActionToast, duration: 5) {
selectedActionToast = nil
} content: { value in
HStack {
Image(systemName: "arrow.uturn.left").foregroundColor(.white)
Text(value).foregroundColor(.white)
Spacer()
Text("Undo").bold().foregroundColor(.yellow)
}
.padding()
.background(Color.orange)
.cornerRadius(20)
}
.easyToast
is still available for backward compatibility, but is deprecated. Please migrate to .toast
and .toast(item:)
for new code.
EasyToast is released under the MIT License. See LICENSE for details.
Keywords: SwiftUI toast, toast notification, custom toast, iOS, macOS, Swift Package Manager, SPM, SwiftUI library