Skip to content

brabanod/Toast

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

8 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🍞 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/brabanod/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.")
    })

About

🍞 Apple Style Toast with Swift

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages