Use the example app to experiment with these different properties
// Create confetti view
let confettiView = ConfettiView(frame: self.view.bounds)
// Add confetti view as subview
self.view.addSubview(confettiView)
// Start the confetti π
confettiView.start()
The confetti animation can be started and stopped by calling the start()
and stop()
methods.
confettiView.start()
confettiView.stop()
To immediately clear all confetti on stopping, the clear
argument can be given as true
:
confettiView.stop(clear: true)
To check whether the confetti animation is active, get the confettiView.animating
property.
LBConfettiView contains four built-in confetti styles, .confetti
, .diamond
, .star
and .triangle
. To use these:
confettiView.style = .confetti
confettiView.style = .diamond
confettiView.style = .star
confettiView.style = .triangle
To use a custom image template for the confetti, use the .customImage
style
confettiView.type = .customImage(UIImage(named: "customImage"))
Set the colors of the confetti with the colors
property. This property has a default value of multiple colors.
confettiView.colors = [UIColor.red, UIColor.green, UIColor.blue]
Two confetti sizes are built-in: .small
and .large
. Using .auto
, the default, will use the large scale on iPads and the small scale on other iOS devices.
confettiView.scale = .auto
A manual scale can also be provided as a CGFloat
using .custom
confettiView.scale = .custom(0.8)
The intensity refers to how many particles are generated and how quickly they fall. Set the intensity of the confetti with the .intensity
property by passing in a value between 0 and 1. The default intensity is 0.5.
confettiView.intensity = 0.75
LBConfettiView is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'LBConfettiView'
LBConfettiView can also be installed manually. Just download and drop the Sources
folder in your project. Alternatively, add LBConfettiView.xcodeproj
to your workspace and embed the framework binary.
Inspired by SAConfettiView by Sudeep Agarwal, which this was originally a modernised reimplementation of.
Lachlan Bell <[email protected]>
Contributions are welcome, see the CONTRIBUTING for more details.