banghuazhao/EasyToast
EasyToast is a lightweight and customizable SwiftUI package that provides easy-to-use toast notifications. Display brief messages to your users with minimal effort.
πΈ Screenshots
<p align="center"> <img src="screenshots/1.png" width="220" /> <img src="screenshots/2.png" width="220" /> <img src="screenshots/3.png" width="220" /> </p>
π Table of Contents
- πΈ Screenshots - π Table of Contents - β¨ Features - β Why EasyToast? - π» Installation - Swift Package Manager - π Getting Started - π Usage - Simple Toast - Toast on Top - Customization - Predefined Types - π Item-based \& Custom Toasts - Item-based Toast - Advanced Custom Toasts - π°οΈ Backward Compatibility - License
β¨ Features
- 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.
β Why EasyToast?
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.
π» Installation
Swift Package Manager
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.
π Getting Started
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!")
}
}π Usage
Simple Toast
.toast(isPresented: $showToast, message: "This is a toast message!")Toast on Top
.toast(isPresented: $showToast, message: "On Top", position: .top)Customization
.toast(
isPresented: $showToast,
message: "Custom Style",
style: ToastStyle(backgroundColor: .blue, textColor: .white)
)Predefined Types
.toast(isPresented: $showToast, message: "Success!", type: .success)π Item-based & Custom Toasts
Item-based Toast
@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)
}Advanced Custom Toasts
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)
}π°οΈ Backward Compatibility
.easyToast is still available for backward compatibility, but is deprecated. Please migrate to .toast and .toast(item:) for new code.
License
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
Package Metadata
Repository: banghuazhao/EasyToast
Stars: 9
Forks: 0
Open issues: 0
Default branch: main
Primary language: swift
License: MIT
Topics: custom-toast, ios, ios-development, lightweight, notifications, popup, swift, swift-package, swift5, swiftpackage, swiftui, swiftui-library, toast, toast-message, toast-notifications, toastnotifications
README: README.md