Danny182 Danny182 - 7 months ago 174
iOS Question

Convert Apple Emoji (String) to UIImage

I need all Apple Emojis.
I can get all the emojis and put them into a String by copying them from the site getemoji but in my app i need the emojis in the right order as images.

Is there a nice way to convert the emojis I copy into a String to a UIImage?

Or a better solution to get all the Apple emojis in the right order?


Add this extension to your project

extension String {
    func image() -> UIImage {
        let size = CGSize(width: 30, height: 35)
        UIGraphicsBeginImageContextWithOptions(size, false, 0);
        let rect = CGRect(origin: CGPointZero, size: size)
        UIRectFill(CGRect(origin: CGPointZero, size: size))
        (self as NSString).drawInRect(rect, withAttributes: [NSFontAttributeName: UIFont.systemFontOfSize(30)])
        let image = UIGraphicsGetImageFromCurrentImageContext()
        return image


The code above draws the current String to an Image Context with a white background color and finally transform it into a UIImage.

Now you can write

enter image description here