https://github.com/simonbs/confettikit
๐ A Swift package for shooting confetti.
https://github.com/simonbs/confettikit
Last synced: 8 months ago
JSON representation
๐ A Swift package for shooting confetti.
- Host: GitHub
- URL: https://github.com/simonbs/confettikit
- Owner: simonbs
- License: mit
- Created: 2022-04-02T09:32:51.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-08-18T03:06:08.000Z (almost 2 years ago)
- Last Synced: 2025-07-05T23:34:42.211Z (12 months ago)
- Language: Swift
- Homepage:
- Size: 1.93 MB
- Stars: 61
- Watchers: 2
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# ๐ ConfettiKit
A Swift package for shooting confetti. The implementation is heavily inspired by the blog post [Recreating iMessage Confetti](https://bryce.co/recreating-imessage-confetti/) by [Bryce Bostwick](https://mastodon.bryce.co/@bryce).
## ๐ฆ Adding the Package
ConfettiKit is distributed using [Swift Package Manager](https://www.swift.org/documentation/package-manager/). Install ConfettiKit in a project by adding it as a dependency in your Package.swift manifest or through โPackage Dependenciesโ in project settings.
```swift
let package = Package(
dependencies: [
.package(url: "git@github.com:simonbs/ConfettiKit.git", from: "1.0.0")
]
)
```
## ๐ Getting Started
Start by creating an instance of ConfettiView and pass an array of UIImage's when doing so. Make sure to add the view to your view hierarchy.
```swift
final class ViewController: UIViewController {
private let confettiView: ConfettiView = {
let images: [UIImage] = [...]
let this = ConfettiView(images: images)
this.translatesAutoresizingMaskIntoConstraints = false
return this
}()
override func viewDidLoad() {
super.viewDidLoad()
view.addSubview(confettiView)
NSLayoutConstraint.activate([
confettiView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
confettiView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
confettiView.topAnchor.constraint(equalTo: view.topAnchor),
confettiView.bottomAnchor.constraint(equalTo: view.bottomAnchor)
])
}
}
```
When you want to shoot confetti, for example in response to a user interaction, call the `shoot()` function on the confetti view.
```swift
confettiView.shoot()
```
By default, ConfettiView shoots confetti from the top to the bottom, creating the effect shown below.

You may configure it to shoot confetti from the center to the left of the screen.
```swift
let images: [UIImage] = [...]
let confettiView = ConfettiView(mode: .centerToLeft, images: images)
```
This can be used to create the effect shown below.

## ๐จโ๐ป Contributing
ConfettiKit was specifically built to be used in my side projects, including [Runestone Text Editor](https://apps.apple.com/us/app/runestone-editor/id1548193893) and [Re: Toot](https://apps.apple.com/us/app/re-toot/id1661697436), so its API might be limited. However, pull requests with bug fixes and new features are much appreciated. I'll be happy to review and merge them once they're ready, as long as they align with the vision of ConfettiKit and offer generally useful functionality.
Clone the repository to get started working on the project.
```bash
git clone git@github.com:simonbs/ConfettiKit.git
```