iOS Library for Presenting Toast Message in UIKit & SwiftUI
Easy to Use, Easy to Customize || Convenient and Consistent
Quick Toast | Detailed Toast | Animation Customized Toast | Top Toast |
---|---|---|---|
1.mp4 |
2.mp4 |
3.mp4 |
4.mp4 |
- You can simply initialize
CLToast
and present. - You can use
CLToastStyle
struct to manage toast message’s Title, Description, Image, and Timeline. - Basic animation/transition(offset & opacity) is provided by the framework.
- You can customize animation/transition with your own taste.
- In UIKit, you will conform the protocol
CLToastUIKitAnimation
. - Otherwise, In SwiftUI, you will conform the protocol
CLToastSwiftUITransition
.
👀 Let's see how it works!
- With
CLToast
, You can present a toast message using several methods. - Whether you use UIKit or SwiftUI,
CLToast
can be used consistently. - Follow the examples below.
// UIKit
CLToast(title: "Title", height: 50)
.present(in: view)
// SwiftUI
var body: some View {
YourView { /* code */ }
.presentToast(
isPresented: $isPresented,
title: "Title",
height: 50
)
}
CLToastStyle
can be used in UIKit and SwiftUI equally.- You can make common style and use it consistently in UIKit and SwiftUI.
// Common style
var style = CLToastStyle(title: "Title")
style.description = "Description"
style.timeline = Date().formatted()
style.image = UIImage(named: "MyImage")
// UIKit
CLToast(with: style)
.present(in: view)
// SwiftUI
var body: some View {
YourView { /* code */ }
.presentToast(
isPresented: $isPresented,
with: style
)
}
- You can present your toast message from top, center and bottom.
CLToast
will present your toast from bottom by default.- in Quick Present, you can’t present it from other direction but bottom.
- Default animation will be automatically adjusted by its presentation section.
var style = CLToastStyle(title: "Title")
style.description = "Description"
style.timeline = Date().formatted()
style.image = UIImage(named: "MyImage")
// UIKit
CLToast(with: style, section: .top)
.present(in: view)
// SwiftUI
var body: some View {
YourView { /* code */ }
.presentToast(
isPresented: $isPresented,
with: style,
section: .top
)
}
- You can customize toast message’s animation/transition.
- You have to make an implementation of
CLToastUIKitAnimation
orCLToastSwiftUITransition
. - Each of protocol will provide you a blueprint.
- WORK IN PROCESS!
// 1. First, you need ``CLToastAnimations`` which has animationSpeed and displayTime, etc.
// This animation model is also can be used commonly in UIKit, and SwiftUI.
var animation = CLToastAnimations()
animation.animatonSpeed = 0.5
animation.displayTime = 1.5
// 2. Then you make an implementation of ``CLToastUIKitAnimation`` or ``CLToastSwiftUITransition``.
struct MyCLToastAnimation: CLToastUIKitAnimation {
let toastAnimations: CLToastAnimations
// 3. Here, You make an animation for when the toast message is appearing.
func makeAppearingAnimation(toastView: UIView, for style: CLToastStyle) {
toastView.layer.opacity = toastAnimations.opacity
toastView.frame.origin.y += toastAnimation.offsetY
toastView.frame.origin.x += 40
}
// 4. Make an animation for when the toast message is disappearing.
func makeDisappearingAnimation(toastView: UIView, for style: CLToastStyle) {
toastView.layer.opacity = 0
toastView.frame.origin.y -= toastAnimation.offsetY
}
// 5. Make an animator which manages above animations.
func makeAnimation() -> UIViewPropertyAnimator {
return UIViewPropertyAnimator(
duration: toastAnimations.animationSpeed,
curve: .easeInOut
)
}
}
// 6. With above CLToastAnimations, initialize your animation implementation.
let animationImplementation = MyCLToastAnimation(toastAnimations: animation)
// 7. ✨ And it's done!
CLToast(with: style, animation: animationImplementation)
.present(in: view)
pod 'CLToaster'
Package URL: https://github.com/ValseLee/CLToaster/
branch: `main`
WORK-IN-PROCESS
CLToaster
is in beta, so it would be updating continuously.
And it might take some time to update below items.
View Customize | Animation Customize | Gesture Customize | Apply Queue | 🚏 More | |
---|---|---|---|---|---|
UIKit | ✅ | ||||
SwiftUI | ✅ |
- Your idea and issue really matter.
- Tell me with issue or fork this repository and make PR to contribute!