Easy to use toast for iOS, styled like Apple's system toasts.
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")
]
)
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()
This package offers various options to customize you toast.
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)
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)
You can change the toast's background color.
toast
.color(.lightGray)
You can change the duration, how long the toast is shown before it is automatically hidden.
toast
.duration(4.2)
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)
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)
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.")
})