LBConfettiView
Usage
Use the example app to experiment with these different properties
Basic Usage
// Create confetti view
let confettiView = ConfettiView(frame: self.view.bounds)
// Add confetti view as subview
self.view.addSubview(confettiView)
// Start the confetti 🎉
confettiView.start()
Animation
The confetti animation can be started and stopped by calling the start()
and stop()
methods.
Starting
confettiView.start()
Stopping
confettiView.stop()
To immediately clear all confetti on stopping, the clear
argument can be given as true
:
confettiView.stop(clear: true)
Animation Status
To check whether the confetti animation is active, get the confettiView.animating
property.
Styles
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"))
Colors
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]
Scale
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)
Intensity
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
Installation
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.
Credit
Inspired by SAConfettiView by Sudeep Agarwal, which this was originally a modernised reimplementation of.
Author
Lachlan Bell <[email protected]>
Contributing
Contributions are welcome, see the CONTRIBUTING for more details.