Toast-Swift
A Swift Toast view - iOS 14 style - built with UIKit.
Installation
Swift Package Manager
You can use The Swift Package Manager to install Toast-Swift by adding the description to your Package.swift file:
CocoaPods
Usage
To create a simple text based toast:
Or add a subtitle:
If you want to add an icon, use the default
method to construct a toast:
Want to use a different layout, but still use the Apple style? Create your own view and inject it into the AppleToastView
class when creating a custom toast:
The show
method accepts several optional parameters. haptic
of type UINotificationFeedbackGenerator.FeedbackType
to use haptics and after
of type TimeInterval
to show the toast after a certain amount of time:
Configuration options
The text
, default
and custom
methods support custom configuration options. The following options are available:
Name | Description | Type | Default |
---|---|---|---|
autoHide |
When set to true, the toast will automatically close itself after display time has elapsed. | Bool |
true |
displayTime |
The duration the toast will be displayed before it will close when autoHide set to true. | TimeInterval |
4 |
animationTime |
Duration of the show and close animation. | TimeInterval |
0.2 |
attachTo |
The view which the toast view will be attached to. | UIView |
nil |
Custom toast view
Don't like the default Apple'ish style? No problem, it is also possible to use a custom toast view with the custom
method. Firstly, create a class that confirms to the ToastView
protocol:
Use your custom view with the custom
construct method on Toast
: