Swiftpack.co -  Package - columbbus/Toast
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
columbbus/Toast
🍞 Apple Style Toast with Swift
.package(url: "https://github.com/columbbus/Toast.git", from: "1.0.0")

🍞 Toast

Easy to use toast for iOS, styled like Apple's system toasts.

Toast


Installation

Swift Package Manager

Add Toast as a dependency in your Package.swift file:

let package = Package(
    dependencies: [
        .Package(url: "https://github.com/columbbus/Toast", from: "1.0.0")
    ]
)

Usage

To show a toast in your UIViewController, simply use

import Toast

Toast()
    .text("Carl's AirPods", subtitle: "Connected")
    .show(in: self)

The toast is then displayed and automatically vanishes after 2 seconds. You can also hide the toast manually by calling

toast.hide()

Options

This package offers various options to customize you toast.

Font

You can change the font for both (title and subtitle) labels or for each label individually.

toast
    .font(UIFont.boldSystemFont(ofSize: 8.0))
    
toast
    .font(
        titleLabel: largeFont,
        subtitleLabel: smallFont)

Text Color

You can change the text color for both (title and subtitle) labels or for each label individually.

toast
    .textColor(.blue)
    
toast
    .textColor(
        titleLabel: .red,
        subtitleLabel: .orange)

Background Color

You can change the toast's background color.

toast
    .color(.lightGray)

Duration

You can change the duration, how long the toast is shown before it is automatically hidden.

toast
    .duration(4.2)

Layout

You can change the layout of the toast. Either both title and subtitle label are displayed, or only the title label is displayed.

toast
    .layout(.title)
    
    toast
        .layout(.titleAndSubtitle)

Accessory View

The toast can have an additional view or image left to the toast message. This accessory is sized 26x26 pixels. The accessory view may contain a custom animation.

toast
    .image(UIImage(systemName: "bell")!)
    
toast
    .accessoryView(myCustomView)

Handlers

Toast has 4 handler, that may be assigned, which get called on specific actions:

  • Start of the show animation
  • Completion of the show animation
  • Start of the hide animation
  • Completion of the hide animation
toast
    .addHandler(startHide: {
        print("Starting SHOW ...")
    })
    .addHandler(showCompletion: {
        print("Finished SHOW.")
    })
    .addHandler(startHide: {
        print("Starting HIDE ...")
    })
    .addHandler(hideCompletion: {
        print("Finished HIDE.")
    })

GitHub

link
Stars: 0
Last commit: 4 days ago

Release Notes

1.0.0
4 days ago

Initial Release

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