Swiftpack.co - jebenjamin/SwiftUIToast as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by jebenjamin.
jebenjamin/SwiftUIToast 1.0.2
A Swift package for displaying sleek iOS-style toast notifications.
⭐️ 0
🕓 6 days ago
iOS macCatalyst
.package(url: "https://github.com/jebenjamin/SwiftUIToast.git", from: "1.0.2")

SwiftUIToast

A package for displaying sleek iOS-style toast notifications with SwiftUI. It's intended to mimic the toasts seen when charging an Apple Pencil or connecting AirPods.

Examples

Setup

Swift Package Manager

SwiftUIToast is a Swift package that can be installed through the 'Package Dependencies' list in your Xcode project. Or, you can add the following line to your own Package.swift file:

dependencies: [
    .package(url: "https://github.com/jebenjamin/SwiftUIToast", from: "1.0.2")
]

CocoaPods

Add the following line to your PodFile:

pod 'SwiftUIToast'

Manually

Drag and drop the SwiftUIToast folder into your project.

Usage

SwiftUIToast is built for SwiftUI. Use a ZStack to layer a ToastView on top of the view you want to display a toast for. Like so:

ZStack {
    ToastView(
        title: "Title",
        subtitle: "Subtitle",
        position: .top,
        duration: 5)
    
    Text("Placeholder")
    // and some other views...
}

Once the toast fades out, the view is removed from the hierarchy. The view automatically adapts to the current color scheme (light or dark mode).

Options

  • image: A SwiftUI Image displayed on the left side of the toast. Optional.
  • title: A title string that will be displayed at the top of the toast. Required.
  • subtitle: A subtitle string that will be displayed at the bottom of the toast. Optional.
  • position: .top places the toast at the top of the stack, .bottom places it at the bottom. Required.
  • duration: A double referring to the number of seconds the toast is displayed. Optional. If empty, the toast will remain fixed in position for the lifecycle of the view. Otherwise, it will fade out once the duration has elapsed.

Compatibility

Requires iOS 13.0+ or Mac Catalyst 13.0+.

License

SwiftUIToast uses the MIT license. A copy is available in LICENSE.

GitHub

link
Stars: 0
Last commit: 5 days ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Related Packages

Release Notes

v1.0.2 - Reduced shadow
5 days ago

This update reduces the ToastView shadow from 7 to 5.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics