EasyToast is a lightweight and customizable SwiftUI package that provides easy-to-use toast notifications. Display brief messages to your users with minimal effort.
- Simple Text Toasts: Display a quick message to the user with just a few lines of code.
- Custom Toast Views: Create and display fully custom-designed toast notifications.
- 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: Control background color, text color, corner radius, font, padding, shadow, and text alignment
- Interactive toasts: Working in progress 🔨
- Toast queueing: Working in progress 🔨
- Improved animations: Working in progress 🔨
- Internationalization: Working in progress 🔨
- Accessibility support: Working in progress 🔨
- iOS 15.0+
- Swift 5+
You can add EasyToast to your project using Swift Package Manager.
- Open your project in Xcode.
- Go to
File > Add Packages Dependencies...
- Enter the package URL: https://github.com/banghuazhao/EasyToast
- Choose the latest release
Alternatively, add the following to your Package.swift
file:
dependencies: [
.package(url: "https://github.com/banghuazhao/EasyToast.git", from: "0.1")
]
To display a simple toast with a message, use the easyToast
modifier:
import EasyToast
struct ContentView: View {
@State private var showToast = false
var body: some View {
content
.easyToast(isPresented: $showToast, message: "Hello, EasyToast!")
}
}
To display a simple toast with a message, use the easyToast
modifier:
var body: some View {
content
.easyToast(isPresented: $showToast, message: "This is a toast message on top", position: .top)
}
Customize the appearance and behavior:
let customStyle = ToastStyle(
backgroundColor: .blue,
textColor: .white,
font: .headline,
cornerRadius: 12,
shadow: .gray,
padding: EdgeInsets(top: 16, leading: 16, bottom: 16, trailing: 16)
)
Text("Custom Toast")
.easyToast(
isPresented: $showToast,
message: "This is a custom toast message.",
position: .bottom,
duration: 3
style: customStyle
)
To display a custom-designed toast view, use the easyToast
modifier with a custom view:
var body: some View {
content
.customToast(isPresented: $showToast, duration: 3, position: .bottom) {
HStack {
Image(systemName: "checkmark.circle")
.foregroundColor(.white)
Text("Show Custom Toast Success")
.foregroundColor(.white)
}
.padding()
.background(Color.green)
.cornerRadius(20)
}
}
The toast is implemented by overlaying a custom view on top of the view that applies the .easyToast
modifier, ensuring it seamlessly appears over the current content without disrupting the underlying layout
EasyToast is released under the MIT License. See LICENSE for details.