This is a SwiftUI view that displays confetti. You can use this package via SPM (Swift Package Manager).
This is beta release. Some of implementation might be changed incompatibly.
confetti.mov
Confetto are generated with random shape/scale/angle every time.
- Xcode 15.0
- iOS 15+
Add this SPM package to your Xcode project.
File
>Add Package Dependencies...
- Input
https://github.com/ottijp/confetti-swiftui
in search box. - Select
Confetti
. - Select
Dependency Rule
toUp to Next Major Version
. (optional, recommended)
Import Confetti
module and add ConfettiView
on your view stack with ZStack.
import SwiftUI
import Confetti
struct SampleView1: View {
var body: some View {
ZStack {
Text("Confetti")
ConfettiView()
}
}
}
You can controll display timing like bellow.
import SwiftUI
import Confetti
struct SampleView2: View {
@State private var isConffetiActive = false
var body: some View {
ZStack {
VStack {
Spacer()
HStack {
Toggle(isOn: $isConffetiActive) {
Text("confetti")
}
.frame(width: 150)
}
}
if isConffetiActive {
ConfettiView()
}
}
}
}
You can set the emission duration with emissionDuration
property.
Default duration is 2 seconds.
// emit for 5 seconds
ConfettiView(emissionDuration: 5.0)
MIT