Skip to content

Repository files navigation

Toaster

Build StatusSwiftCocoaPodsCarthage compatible

Android-like toast with very simple interface. (formerly JLToast)

Screenshots

Toaster Screenshot

Features

  • Queueing: Centralized toast center manages the toast queue.
  • Customizable: See the Appearance section.
  • String or AttributedString: Both supported.
  • UIAccessibility: VoiceOver support.

At a Glance

import Toaster
Toast(text:"Hello, world!").show()

Compatibility

Toaster supports the same minimum Xcode version as App Store submission (https://developer.apple.com/ios/submit/):

  • Xcode 15 and newer

Toaster supports the same Swift versions as Xcode (https://developer.apple.com/support/xcode/):

  • Swift 4 and newer

Toaster supports all Apple platforms.

Installation

  • For projects with CocoaPods:

    pod'Toaster'
  • For projects with Carthage:

    github "devxoul/Toaster"
    
  • For projects with Swift Package Manager:

    dependencies: [
    .package(url: "https://github.com/devxoul/Toaster.git", from: "master")
    ]
    

Getting Started

Setting Duration and Delay

Toast(text:"Hello, world!", duration:Delay.long)Toast(text:"Hello, world!", delay:Delay.short, duration:Delay.long)

Removing Toasts

  • Removing toast with reference:

    lettoast=Toast(text:"Hello")
    toast.show()
    toast.cancel() // remove toast immediately
  • Removing current toast:

    iflet currentToast =ToastCenter.default.currentToast {
    currentToast.cancel()}
  • Removing all toasts:

    ToastCenter.default.cancelAll()

Appearance

Since Toaster 2.0.0, you can use UIAppearance to set default appearance. This is an short example to set default background color to red.

ToastView.appearance().backgroundColor =.red

Supported appearance properties are:

PropertyTypeDescription
backgroundColorUIColorBackground color
cornerRadiusCGFloatCorner radius
textInsetsUIEdgeInsetsText inset
textColorUIColorText color
fontUIFontFont
bottomOffsetPortraitCGFloatVertical offfset from bottom in portrait mode
bottomOffsetLandscapeCGFloatVertical offfset from bottom in landscape mode
shadowPathCGPathThe shape of the layer’s shadow
shadowColorUIColorThe color of the layer’s shadow
shadowOpacityFloatThe opacity of the layer’s shadow
shadowOffsetCGSizeThe offset (in points) of the layer’s shadow
shadowRadiusCGFloatThe blur radius (in points) used to render the layer’s shadow
maxWidthRatioCGFloatThe width ratio of toast view in window
useSafeAreaForBottomOffsetBoolA Boolean value that determines safeAreaInsets.bottom is added to bottomOffset

Attributed string

Since Toaster 2.3.0, you can also set an attributed string:

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

Accessibility

By default, VoiceOver with UIAccessibility is enabled since Toaster 2.3.0. To disable it:

ToastCenter.default.isSupportAccessibility =false

License

Toaster is under WTFPL. You can do what the fuck you want with Toast. See LICENSE file for more info.

About

🍞 Toast for Swift

Topics

Resources

Stars

1.9k stars

Watchers

31 watching

Forks

Releases

Packages

Used by

Contributors

Languages