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

Add support for multiple images and emojis #28

Open
Liampronan opened this issue Oct 1, 2016 · 10 comments
Open

Add support for multiple images and emojis #28

Liampronan opened this issue Oct 1, 2016 · 10 comments

Comments

@Liampronan
Copy link

I'm working on a fork that adds three new types: .images, .emoji, and .emojis. If there's any interest, I can open a PR -- let me know if so!

In the spirit of the this repo's demos, here's a (albeit low-quality) gif :

emoji_multi_image_confetti

@saldous
Copy link

saldous commented Jan 9, 2017

yes please!

@jaymutzafi
Copy link

@Liampronan Did you ever make the emoji version?

@Liampronan
Copy link
Author

I did but haven't submitted a PR -- is this library still maintained?

@jaymutzafi
Copy link

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.

@Liampronan
Copy link
Author

@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!
    }
    
}

image

@jaymutzafi
Copy link

Splendid! Thank you.

@Liampronan
Copy link
Author

👍 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

@jaymutzafi
Copy link

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()

@Liampronan
Copy link
Author

did you add teh extension from the above code snippet? it adds .image() to String

@jaymutzafi
Copy link

Ah silly me, I messed it up. Looks good. (that's pretty clever btw, nicely done)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants