matthew-2000/swifttoast
**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.
π About SwiftToast
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.
β¨ Features
- π 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)
π¦ Installation
Using 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.
π Usage
1οΈβ£ Basic Usage
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!")
}
}2οΈβ£ Customization
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
)π¨ Customization Options:
| 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(...) |
π Animations
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)
)Available animations:
.fadeβ Simple fade in/out.slideβ Smooth slide transition.bounceβ Spring-like bounce effect.scaleβ Scale-in effect.custom(Animation)β Use your own animation
β Testing
To run unit tests:
swift testOr, in Xcode: Cmd + U to run all tests.
π Contributing
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 π
π License
This project is licensed under the MIT License - see the LICENSE file for details.
π‘ Credits
Developed by Matteo Ercolino β’ GitHub
π’ Support
If you find this project useful, βοΈ star the repository and share it with others!
π Happy coding with SwiftToast! π
Package Metadata
Repository: matthew-2000/swifttoast
Default branch: main
README: README.md