ConfettiView
ConfettiView copied to clipboard
Possibility to add images instead of shapes?
Hi there,
Great pod! I'm looking for a way to provide my own images. What I've done right now is this:
ImageView.swift
import UIKit
class ImageView: UIView {
var possibleColors:[UIColor] = [#colorLiteral(red: 0, green: 0.4443781972, blue: 0.8679092526, alpha: 1),#colorLiteral(red: 0.5667363405, green: 0.8658216596, blue: 0.4901404977, alpha: 1),#colorLiteral(red: 1, green: 0.9203848839, blue: 0.331726253, alpha: 1),#colorLiteral(red: 0.9978461862, green: 0.3002898395, blue: 0.2846045196, alpha: 1),#colorLiteral(red: 0.7954284549, green: 0.3837707639, blue: 0.7679683566, alpha: 1)]
override init(frame: CGRect) {
super.init(frame: frame)
self.backgroundColor = UIColor.clear
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
/**
Initialize a new shape view with random shape and color
- Parameters:
- center: The center position of the initiaized view
- depth: The wanted depth, this causes the shape to move faster and apear smaller to create the illusion of depth *Default Value is 1*
*/
convenience init(center point:CGPoint, depth:Double = 1, image: UIImage) {
self.init(frame:CGRect(x: 0, y: 0, width: 20/depth, height: 20/depth))
self.center = point
let index: Int = Int(arc4random_uniform(UInt32(self.possibleColors.count)))
let color: UIColor = self.possibleColors[index]
let imageView = UIImageView(image: image.withRenderingMode(.alwaysTemplate))
imageView.tintColor = color
imageView.frame = self.frame
self.addSubview(imageView)
}
}
It works kind of okay, but some images are spinning pretty weird. And some images are appearing suddenly in the view.
Can we find a way to improve this, so this pod can be even more awesome 👍 ?
Thanks!
Hi @wouterwisselink
Sounds like a good addition to the library. I added this as a feature for 0.8 milestone which will be released fairly soon.
Thanks! Or.