Add support for multiple images and emojis
Opened this issue ยท 10 comments
yes please!
@Liampronan Did you ever make the emoji version?
I did but haven't submitted a PR -- is this library still maintained?
I don't know. But if you have a version I would love a peak at it. Actually all I'm trying to do is use a custom image but without having the color overlay on it and it also happens that the image I am using was taken from the bacon emoji so i wanted to see if your version helps me here.
@jaymutzafi basic implementation:
import SAConfettiView
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let confettiView = SAConfettiView(frame: self.view.bounds)
confettiView.type = .Image("๐ฅ".image())
confettiView.colors = [UIColor.white]
confettiView.startConfetti()
view.addSubview(confettiView)
}
}
extension String {
func image() -> UIImage {
let size = CGSize(width: 30, height: 35)
UIGraphicsBeginImageContextWithOptions(size, false, 0);
UIColor.clear.set()
let rect = CGRect(origin: CGPoint.zero, size: size)
UIRectFill(CGRect(origin: CGPoint.zero, size: size))
(self as NSString).draw(in: rect, withAttributes: [NSFontAttributeName: UIFont.systemFont(ofSize: 30)])
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return image!
}
}
Splendid! Thank you.
๐ for images in general, you may need to ensure you call confettiView.colors = [UIColor.white]
before startConfetti()
-- it looks like setting colors doesn't reset the confettiView colors if it's already animating. haven't tested that out recently w/ non-emoji images but I'd imagine similar funcitonality
Yeah .white solved my color problem, so I'm all good! But out of curiosity I've tried "๐ฅ".image() and it says string has no member .image()
did you add teh extension from the above code snippet? it adds .image()
to String
Ah silly me, I messed it up. Looks good. (that's pretty clever btw, nicely done)