Increase the font size of emoji characters in a UITextView in iOS 5.x

后端 未结 2 1899
灰色年华
灰色年华 2021-01-02 14:42

If I have UITextView and set the font size to, say 32. When I run the application (in both simulator and on the device), I see a large cursor and text that I type appears ju

相关标签:
2条回答
  • 2021-01-02 15:03

    You can scale emojis up with ANY font is 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.

    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;
    
    0 讨论(0)
  • 2021-01-02 15:11

    Have you tried setting the UITextView's font to AppleColorEmoji as well? On iOS, it seems that AppleColorEmoji is the only font that will draw scaled-up emoji. Use any other font, and the emoji never get larger than about 20x20 pixels, as you've noticed.

    I did my tests using this handy free app called Fonts!, which is a nice way of getting quick feedback on the actual device itself.

    I note that the Game Center app seems to be able to mix an interesting font with scaled-up emoji, so clearly it IS possible to do better than the (rather pedestrian) emoji font! I don't know whether this is something special in its code, though, or something special about the font it uses, which looks like a custom one.

    0 讨论(0)
提交回复
热议问题