Skip to content

Commit

Permalink
Add confetti types
Browse files Browse the repository at this point in the history
  • Loading branch information
Sudeep Agarwal committed Dec 15, 2015
1 parent 2bdf2fc commit c9fdcd3
Show file tree
Hide file tree
Showing 15 changed files with 156 additions and 80 deletions.
4 changes: 2 additions & 2 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PODS:
- SAConfettiView (0.1.1)
- SAConfettiView (0.1.3)

DEPENDENCIES:
- SAConfettiView (from `../`)
Expand All @@ -9,6 +9,6 @@ EXTERNAL SOURCES:
:path: ../

SPEC CHECKSUMS:
SAConfettiView: 923e85c40c8815cb0ea8c0b1c64f1ba9cf64bfbe
SAConfettiView: 91d2fb2ddf07725ad9d599349617382b91452ede

COCOAPODS: 0.39.0
4 changes: 2 additions & 2 deletions Example/Pods/Local Podspecs/SAConfettiView.podspec.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Example/Pods/Manifest.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

158 changes: 91 additions & 67 deletions Example/Pods/Pods.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"images" : [
{
"idiom" : "universal",
"filename" : "confetti.png",
"filename" : "diamond.png",
"scale" : "1x"
},
{
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions Example/SAConfettiView/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ class ViewController: UIViewController {
// Set intensity (from 0 - 1, default intensity is 0.5)
confettiView.intensity = 0.5

// Set type
confettiView.type = .Diamond

// For custom image
// confettiView.type = .Custom
// confettiView.customImage = UIImage(named: "diamond")

// Add subview
view.addSubview(confettiView)
}
Expand Down
Binary file added Pod/Assets/diamond.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Pod/Assets/star.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Pod/Assets/triangle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
51 changes: 48 additions & 3 deletions Pod/Classes/SAConfettiView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,34 @@ import UIKit
import QuartzCore

public class SAConfettiView: UIView {

public enum ConfettiType {
case Confetti
case Triangle
case Star
case Diamond
case Custom
}

var emitter: CAEmitterLayer!
public var colors = [UIColor.redColor(), UIColor.greenColor(), UIColor.blueColor()]
public var intensity: Float = 0.5
public var colors: [UIColor]!
public var intensity: Float!
public var type: ConfettiType!
public var customImage: UIImage?

required public init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}

public override init(frame: CGRect) {
super.init(frame: frame)
colors = [UIColor(red:0.95, green:0.40, blue:0.27, alpha:1.0),
UIColor(red:1.00, green:0.78, blue:0.36, alpha:1.0),
UIColor(red:0.48, green:0.78, blue:0.64, alpha:1.0),
UIColor(red:0.30, green:0.76, blue:0.85, alpha:1.0),
UIColor(red:0.58, green:0.39, blue:0.55, alpha:1.0)]
intensity = 0.5
type = .Confetti
}

public func startConfetti() {
Expand All @@ -43,6 +60,34 @@ public class SAConfettiView: UIView {
emitter.birthRate = 0
}

func imageForType(type: ConfettiType) -> UIImage? {

var fileName: String!

switch type {
case .Confetti:
fileName = "confetti"
case .Triangle:
fileName = "triangle"
case .Star:
fileName = "star"
case .Diamond:
fileName = "diamond"
case .Custom:
return customImage
}

let path = NSBundle(forClass: SAConfettiView.self).pathForResource("SAConfettiView", ofType: "bundle")
let bundle = NSBundle(path: path!)
let imagePath = bundle?.pathForResource(fileName, ofType: "png")
let url = NSURL(fileURLWithPath: imagePath!)
let data = NSData(contentsOfURL: url)
if let data = data {
return UIImage(data: data)!
}
return nil
}

func confettiWithColor(color: UIColor) -> CAEmitterCell {
let confetti = CAEmitterCell()
confetti.birthRate = 6.0 * intensity
Expand All @@ -57,7 +102,7 @@ public class SAConfettiView: UIView {
confetti.spinRange = CGFloat(4.0 * intensity)
confetti.scaleRange = CGFloat(intensity)
confetti.scaleSpeed = CGFloat(-0.1 * intensity)
confetti.contents = UIImage(named: "confetti")?.CGImage
confetti.contents = imageForType(type)!.CGImage
return confetti
}

Expand Down
2 changes: 1 addition & 1 deletion SAConfettiView.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = "SAConfettiView"
s.version = "0.1.1"
s.version = "0.1.3"
s.summary = "Confetti! Who doesn't like confetti?'"

# This description is used to generate tags and improve search results.
Expand Down

0 comments on commit c9fdcd3

Please sign in to comment.