Nirav
Nirav

Reputation: 119

iOS App - Emoji Characters Font Size

I have an app where I am using Helvetic fonts with 60.0 Pixels font size for My UILabel. The problem occurs when someone enters the text with Emoji characters. The entire text renders at 60.0 pixel font size, but the emoji characters are not scaled.

P.S. I don't want to use AppleColorEmoji fonts for my normal text. I can't use NSAttributedString as my app supports iOS 5.

Upvotes: 2

Views: 1551

Answers (1)

Albert Renshaw
Albert Renshaw

Reputation: 17902

You can scale emojis up with ANY font if you set the UITextViews contentScaleFactor and then scale the text field using a CGTransform. (You can even scale them up bigger (with high resolution) than AppleColorEmoji allows you to go by default.

So simply set your helvetic font size to match emoji's default font size in helvetica, (maybe 12.0f), then set your scale factor and resolution factor to 2.0f, and make your textView's width and height (frame) 1/2 what it normally would be, then run the code below, and the final product will be a textView who's frame is the right size, your font size is twice what you set it (now 24.0f pt font (INCLUDING EMOJIS)) and the resolution is crystal clear, for both your font (text) and your emojis, as if they had all been that size all along!)

float scaleFactor = 2.0f;
float resolutionFactor = 2.0f;

CGPoint tempCenter = theTextView.center;

theTextView.contentScaleFactor *= resolutionFactor;
theTextView.layer.contentsScale *= resolutionFactor;


for (UIView *subview in [theTextView subviews]) {
    subview.contentScaleFactor *= resolutionFactor;
    subview.layer.contentsScale *= resolutionFactor;
}

theTextView.transform = CGAffineTransformScale(CGAffineTransformIdentity, scaleFactor, scaleFactor);

theTextView.center = tempCenter;

Upvotes: 2

Related Questions