A configurable Swift framework for UI Toast components.
ToastFrameworkSwift is an open-source framework available through CocoaPods.
First step is to install CocoaPods. Skip this step if you already have CocoaPods installed on your machine.
sudo gem install cocoapods
Initialize your project with CocoaPods from your project directory:
pod init
For installation, add the required pod within your Podfile
as shown below:
pod 'ToastFrameworkSwift'
After adding the pod, run the below command :
pod install
To run the example project, clone the repo, and run pod install
within the ToastFrameworkExample directory, using Terminal
.
Here you can see how different types of toasts look, both normal and CTA ones.
After the installation step you should have generated the .xcworkspace
. The next step now is to import ToastFrameworkSwift
within your ViewController
:
import ToastFrameworkSwift
The toast framework can be configured with the following properties:
// Enables or disables tap to dismiss behaviour for toasts.
// When `true`, toast views will dismiss when tapped. When `false`, tapping will have no effect.
ToastManager.shared.isTapToDismissEnabled = true
// Enables or disables wipe to dismiss behaviour for toasts.
// When `true`, toast views will dismiss when swiped. When `false`, swiping will have no effect.
ToastManager.shared.isSwipeToDismissEnabled = true
// Enables or disables queueing behaviour for toasts.
// When `true`, toast views will appear one after the other. When `false`, toast overlapping might happen
ToastManager.shared.isQueueEnabled = true
// The default duration for toasts. Default value is 1.0
ToastManager.shared.duration = 2
// This property sets up the haptic feedback type. The types can be found
// within `HapticFeedback` class. When `.none`, there won't be any haptic feedback.
ToastManager.shared.hapticFeedbackType = .impactLight
func presentBasicToast() {
view.showToast(message: "This is a Basic Toast.")
}
func presentBasicGrayToast() {
view.showToast(message: "This is a Basic Gray Toast.", toastColor: .gray)
}
func presentBasicBlackTextToast() {
view.showToast(message: "This is a Black Text Toast.", toastColor: .gray, textColor: .black)
}
func presentCTAToast() {
view.showCTAToast(message: "This is a CTA Toast.", actionTitle: "Press here") { [weak self] in
self?.view.showToast(message: "This is the follow-up Toast.", toastColor: .systemGreen)
}
}
George Mihoc, george.mihoc@gmail.com
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
MIT @ 2022 George Mihoc