Convert Apple Emoji String to UIImage

0 votes
I require every Apple Emoji.
I can copy all the emojis from the website getemoji and put them into a String, but I need the emojis in the correct order as images for my project.

Can I convert the emojis I copied from a String to a UIImage in a beautiful way?
Or is there a better way to arrange all the Apple emojis correctly?
Sep 22, 2022 in IOS by Soham
• 9,710 points
695 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

Here is a revised response with the following modifications:

Centered: To centre the text within the generated UIImage, draw(at:withAttributes:) was used instead of draw(in:withAttributes:).

Correct Size: Used size(withAttributes:) to produce a UIImage with a size that corresponds to the font's true size.

Comments: Added remarks to aid comprehension

Swift 5

import UIKit
extension String {
    func textToImage() -> UIImage? {
        let nsString = (self as NSString)
        let font = UIFont.systemFont(ofSize: 1024) // you can change your font size here
        let stringAttributes = [NSAttributedString.Key.font: font]
        let imageSize = nsString.size(withAttributes: stringAttributes)

        UIGraphicsBeginImageContextWithOptions(imageSize, false, 0) //  begin image context
        UIColor.clear.set() // clear background
        UIRectFill(CGRect(origin: CGPoint(), size: imageSize)) // set rect size
        nsString.draw(at: CGPoint.zero, withAttributes: stringAttributes) // draw text within rect
        let image = UIGraphicsGetImageFromCurrentImageContext() // create image from context
        UIGraphicsEndImageContext() //  end image context

        return image ?? UIImage()
    }
}

Swift 3.2

import UIKit
extension String {
    func textToImage() -> UIImage? {
        let nsString = (self as NSString)
        let font = UIFont.systemFont(ofSize: 1024) // you can change your font size here
        let stringAttributes = [NSFontAttributeName: font]
        let imageSize = nsString.size(attributes: stringAttributes)

        UIGraphicsBeginImageContextWithOptions(imageSize, false, 0) //  begin image context
        UIColor.clear.set() // clear background
        UIRectFill(CGRect(origin: CGPoint(), size: imageSize)) // set rect size
        nsString.draw(at: CGPoint.zero, withAttributes: stringAttributes) // draw text within rect
        let image = UIGraphicsGetImageFromCurrentImageContext() // create image from context
        UIGraphicsEndImageContext() //  end image context

        return image ?? UIImage()
    }
}
answered Sep 26, 2022 by Rahul
• 9,680 points

edited Mar 5

Related Questions In IOS

0 votes
1 answer

Is there a way to generate high resolution PNGs of iOS emoji?

The glyphs for the "Apple Color Emoji" ...READ MORE

answered Sep 20, 2022 in IOS by Aditya
• 7,680 points
2,649 views
0 votes
1 answer

Is it possible to run .APK/Android apps on iPad/iPhone devices?

It is not possible to run Android ...READ MORE

answered Sep 20, 2022 in IOS by Aditya
• 7,680 points
4,860 views
0 votes
1 answer

How to build a font generator in iOS Swift and allowing pasting to clipboard

On your iPhone, you cannot copy and ...READ MORE

answered Sep 22, 2022 in IOS by Rahul
• 9,680 points
1,233 views
0 votes
1 answer

Is there a way to to check if a picture was taken on that iPhone?

Actually, the model and manufacturer information is ...READ MORE

answered Sep 22, 2022 in IOS by Rahul
• 9,680 points
781 views
0 votes
0 answers

How to connect iphone to a local server running on mac?

I am running a django server at ...READ MORE

Sep 22, 2022 in IOS by Soham
• 9,710 points
827 views
0 votes
0 answers

Angle to Mecca from current location with iPhone compass

I am developing an iPhone application that ...READ MORE

Sep 27, 2022 in IOS by Soham
• 9,710 points
435 views
0 votes
1 answer

Is there a lightweight method to check if emoji is supported in iOS?

You can easily override theme by wrapping ...READ MORE

answered Dec 12, 2022 in Mobile Development by gaurav
• 23,260 points
647 views
0 votes
1 answer

Get User Group in Swift using AWS Cognito

The groups are exposed in the ID ...READ MORE

answered Nov 12, 2018 in AWS by Priyaj
• 58,020 points
1,651 views
0 votes
1 answer

URL Scheme for iOS Home App

I think you could try doing it ...READ MORE

answered Nov 16, 2018 in IoT (Internet of Things) by nirvana
• 3,130 points
1,256 views
0 votes
1 answer

iOS App : Porting Code to App

If you make a post, missing parameters ...READ MORE

answered Jan 18, 2019 in IoT (Internet of Things) by Shubham
• 13,490 points
866 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP