A lightweight Swift package for displaying toast notifications as overlay windows in iOS and iPadOS applications. The library uses SwiftUI for rendering toast messages and works with both UIKit and SwiftUI applications.
- Display any SwiftUI view as a toast message
- Customizable display duration
- Multiple toasts appear in a vertical stack
- Automatic dismissal with animations
- Works in any app state without interfering with existing UI
Add the following to your Package.swift file:
dependencies: [
.package(url: "https://github.com/yourusername/SwiftOverlayToast.git", from: "1.0.0")
]Or add it directly in Xcode:
- File > Swift Packages > Add Package Dependency
- Enter the repository URL:
https://github.com/yourusername/SwiftOverlayToast.git
import SwiftOverlayToast
import SwiftUI
// Show a simple text toast
SwiftOverlayToast.present(
view: Text("Hello, World!")
.padding()
.background(Color.black.opacity(0.7))
.foregroundColor(.white)
.cornerRadius(10),
duration: 2.0
)SwiftOverlayToast.present(
view: HStack {
Image(systemName: "checkmark.circle.fill")
.foregroundColor(.green)
Text("Success!")
}
.padding()
.background(Color.black.opacity(0.7))
.foregroundColor(.white)
.cornerRadius(10),
duration: 3.0
)SwiftOverlayToast.present(
view: VStack {
Text("Action Required")
.font(.headline)
HStack {
Button("Confirm") {
// Do something
SwiftOverlayToast.dismissAll()
}
.padding(.horizontal)
Button("Cancel") {
SwiftOverlayToast.dismissAll()
}
.padding(.horizontal)
}
}
.padding()
.background(Color.black.opacity(0.8))
.foregroundColor(.white)
.cornerRadius(12),
duration: 10.0 // Longer duration for interaction
)SwiftOverlayToast.dismissAll()- iOS 14.0+ / iPadOS 14.0+
- Swift 5.5+
- Xcode 13.0+
This project is available under the MIT license. See the LICENSE file for more info.