Danny182 Danny182 - 1 year ago 345
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?

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download