SwiftToast is a lightweight and customizable SwiftUI library for displaying non-intrusive toast messages in your iOS/macOS applications. Designed for simplicity and flexibility, it allows you to show short notifications with custom styling and animations.
- π Easy to use: Simple API for quick integration
- π¨ Customizable: Change colors, fonts, durations, and positions
- π Smooth animations: Fade, slide, bounce, and more
- π― Positioning: Show toast at the top or bottom of the screen
- π Supports Swift Package Manager (SPM)
- Open your Xcode project.
- Go to File > Add Packages...
- Enter the following URL:
https://github.com/matthew-2000/SwiftToast.git
- Choose Latest Version and click Add Package.
To display a simple toast message:
import SwiftUI
import SwiftToast
struct ContentView: View {
@State private var showToast = false
var body: some View {
VStack {
Button("Show Toast") {
showToast = true
}
}
.toast(isPresented: $showToast, message: "Hello, SwiftToast!")
}
}
You can customize the toast appearance, duration, and position:
.toast(
isPresented: $showToast,
message: "Customized Toast!",
duration: 3,
backgroundColor: .blue,
textColor: .white,
font: .headline,
position: .top,
animationStyle: .bounce
)
Parameter | Type | Default Value | Description |
---|---|---|---|
message |
String |
Required | The toast text |
duration |
TimeInterval |
2 seconds |
How long the toast is visible |
backgroundColor |
Color |
.black.opacity(0.8) |
Background color |
textColor |
Color |
.white |
Text color |
font |
Font |
.body |
Font style |
position |
VerticalAlignment |
.bottom |
.top or .bottom |
animationStyle |
ToastAnimationStyle |
.slide |
.fade , .slide , .bounce , .scale , .custom(...) |
SwiftToast includes built-in animations, or you can add your own:
.toast(
isPresented: $showToast,
message: "Spring animation!",
animationStyle: .spring(response: 0.5, dampingFraction: 0.6)
)
.fade
β Simple fade in/out.slide
β Smooth slide transition.bounce
β Spring-like bounce effect.scale
β Scale-in effect.custom(Animation)
β Use your own animation
To run unit tests:
swift test
Or, in Xcode: Cmd + U to run all tests.
Contributions are welcome! Feel free to open an issue or submit a pull request.
- Fork the repository
- Create a feature branch (
git checkout -b feature-name
) - Commit your changes (
git commit -m "Add new feature"
) - Push to the branch (
git push origin feature-name
) - Open a pull request π
This project is licensed under the MIT License - see the LICENSE file for details.
Developed by Matteo Ercolino β’ GitHub
If you find this project useful, βοΈ star the repository and share it with others!
π Happy coding with SwiftToast! π