Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow multiple types of conffetis #24

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions Example/SAConfettiView/ViewController.swift
Expand Up @@ -35,8 +35,8 @@ class ViewController: UIViewController {
// Set intensity (from 0 - 1, default intensity is 0.5)
confettiView.intensity = 0.5

// Set type
confettiView.type = .Diamond
// Set types
confettiView.types = [ .Diamond, .Confetti, .Star, .Triangle ]

// For custom image
// confettiView.type = .Image(UIImage(named: "diamond")!)
Expand Down
24 changes: 18 additions & 6 deletions Pod/Classes/SAConfettiView.swift
Expand Up @@ -22,9 +22,19 @@ public class SAConfettiView: UIView {
var emitter: CAEmitterLayer!
public var colors: [UIColor]!
public var intensity: Float!
public var type: ConfettiType!
public var types: [ConfettiType]!
private var active :Bool!


@available(*, deprecated=1.0)
public var type: ConfettiType! {
set {
types = [ newValue ]
}
get {
return types.first!
}
}

required public init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
setup()
Expand All @@ -42,7 +52,7 @@ public class SAConfettiView: UIView {
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
types = [ .Confetti ]
active = false
}

Expand All @@ -55,7 +65,9 @@ public class SAConfettiView: UIView {

var cells = [CAEmitterCell]()
for color in colors {
cells.append(confettiWithColor(color))
for type in types {
cells.append(confettiWithColor(color: color, type: type))
}
}

emitter.emitterCells = cells
Expand Down Expand Up @@ -95,8 +107,8 @@ public class SAConfettiView: UIView {
}
return nil
}

func confettiWithColor(color: UIColor) -> CAEmitterCell {
func confettiWithColor(color color: UIColor, type: ConfettiType) -> CAEmitterCell {
let confetti = CAEmitterCell()
confetti.birthRate = 6.0 * intensity
confetti.lifetime = 14.0 * intensity
Expand Down
2 changes: 1 addition & 1 deletion SAConfettiView.podspec
Expand Up @@ -8,7 +8,7 @@

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

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