Toaster Documentation

repository·master·Indexed 23 days ago

https://github.com/devxoul/toaster

An Android-like toast notification library for iOS and Apple platforms. Features a centralized queueing system, support for plain and attributed strings, and global appearance customization via UIAppearance.

Tokens
1.2K
Snippets
5
Records
8
Agent score
34%

What's inside Toaster

  1. Install Toaster via Swift Package Manager, CocoaPods, or Carthage

    master

    You can integrate Toaster into your project using any of the following dependency managers:

    Swift Package Manager Add the following to your Package.swift dependencies:

    CocoaPods Add this to your Podfile:

    Carthage Add this to your Cartfile:

  2. Show a toast with an AttributedString

    master

    Since version 2.3.0, you can pass an NSAttributedString to a Toast to support rich text styling like custom background colors or specific text attributes.

    Toast(attributedText: NSAttributedString(string: "AttributedString Toast", attributes: [NSAttributedString.Key.backgroundColor: UIColor.yellow]))
  3. Configure Accessibility support

    master

    VoiceOver support is enabled by default. If you need to disable UIAccessibility support for toasts, configure it via ToastCenter.default.

    ToastCenter.default.isSupportAccessibility = false
  4. Remove toasts

    master

    Toaster provides several ways to dismiss toasts:

    • Specific toast: Keep a reference to the Toast instance and call .cancel().
    • Current toast: Use ToastCenter.default.currentToast to find and cancel the toast currently being displayed.
    • All toasts: Use ToastCenter.default.cancelAll() to clear the entire queue.
    // Removing toast with reference
    let toast = Toast(text: "Hello")
    toast.show()
    toast.cancel() // remove toast immediately
    
    // Removing current toast
    if let currentToast = ToastCenter.default.currentToast {
        currentToast.cancel()
    }
    
    // Removing all toasts
    ToastCenter.default.cancelAll()
  5. Reference: ToastView appearance properties

    master

    The following properties can be set on ToastView.appearance() to customize the global look of toasts:

    | Property | Type | Description |
    |---|---|---|
    | `backgroundColor` | `UIColor` | Background color |
    | `cornerRadius` | `CGFloat` | Corner radius |
    | `textInsets` | `UIEdgeInsets` | Text inset |
    | `textColor` | `UIColor` | Text color |
    | `font` | `UIFont` | Font |
    | `bottomOffsetPortrait` | `CGFloat` | Vertical offfset from bottom in portrait mode |
    | `bottomOffsetLandscape` | `CGFloat` | Vertical offfset from bottom in landscape mode |
    | `shadowPath` | `CGPath` | The shape of the layer’s shadow |
    | `shadowColor` | `UIColor` | The color of the layer’s shadow |
    | `shadowOpacity` | `Float` | The opacity of the layer’s shadow |
    | `shadowOffset` | `CGSize` | The offset (in points) of the layer’s shadow |
    | `shadowRadius` | `CGFloat` | The blur radius (in points) used to render the layer’s shadow |
    | `maxWidthRatio` | `CGFloat` | The width ratio of toast view in window |
    | `useSafeAreaForBottomOffset` | `Bool` | A Boolean value that determines `safeAreaInsets.bottom` is added to `bottomOffset` |