Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8893341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:13:22+00:00 2026-06-14T23:13:22+00:00

For what apparently is a ‘bug,’ UITextView does not seem to support kerning like

  • 0

For what apparently is a ‘bug,’ UITextView does not seem to support kerning like other UIKit Elements. Is there a workaround to get kerning working?

To be clear, I’m talking about the spacing in between pairs of characters that are defined in the font file, not the general spacing between all characters. Using an NSAttributedString with the NSKernAttributeName will adjust the spacing between all characters, but the built in character pairs still don’t work.

For Example:

enter image description here

Is there a workaround to fix this?

One simple workaround I have discovered is to add css styles to the UITextView which enable kerning. If I use the undocumented method setContentToHTMLString: I can inject the css to the secret webview within the text view.

NSString *css = @"*{text-rendering: optimizeLegibility;}";
NSString *html = [NSString stringWithFormat:@"<html><head><style>%@</style></head><body>Your HTML Text</body></html>", css];
[textView performSelector:@selector(setContentToHTMLString:) withObject:html];

This fixes the problem immediately; however, it seems very likely this will get the app rejected. Is there a safe way to sneak some css into the text view?

Other workarounds I have experimented with include:

Using a webview and the contenteditable property. This isn’t ideal because webview does a bunch of extra stuff that gets in the way, for example the input accessory view which can’t easily be hidden.

Subclassing a UITextView and rendering text manually with core text. This is more complex than I’d hoped because all the selections stuff needs to be reconfigured as well. Because of UITextView‘s private subclasses of UITextPosition and UITextRange this is a huge pain in the ass if not completely impossible.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T23:13:23+00:00Added an answer on June 14, 2026 at 11:13 pm

    You are right that your app would probably be rejected by using @selector(setContentToHTMLString:). You can however use a simple trick to construct the selector dynamically so that it will not be detected during validation.

    NSString *css = @"*{text-rendering: optimizeLegibility;}";
    NSString *html = [NSString stringWithFormat:@"<html><head><style>%@</style></head><body>Your HTML Text</body></html>", css];
    @try {
        SEL setContentToHTMLString = NSSelectorFromString([@[@"set", @"Content", @"To", @"HTML", @"String", @":"] componentsJoinedByString:@""]);
        #pragma clang diagnostic push
        #pragma clang diagnostic ignored "-Warc-performSelector-leaks"
        [textView performSelector:setContentToHTMLString withObject:html];
        #pragma clang diagnostic pop
    }
    @catch (NSException *exception) {
        // html+css could not be applied to text view, so no kerning
    }
    

    By wrapping the call inside a @try/@catch block, you also ensure that your app will not crash if the setContentToHTMLString: method is removed in a future version of iOS.

    Using private APIs is generally not recommended, but in this case I think it totally makes sense to use a small hack vs rewriting UITextView with CoreText.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Apparently, there's been a big brouhaha over whether or not Python needs tail-call optimization
Apparently this function in SDL_Mixer keeps dying, and I'm not sure why. Does anyone
Apparently this code does not work. The problem is described as: Parse error: syntax
Apparently, the PictureBox class does not offer an event when its Image property is
Apparently there's a maximum number of arguments for std::thread for the std::thread implementation in
Apparently mutableCopy copies by reference, not value. Ie if I do this: NSMutableArray arrayA
Apparently (at least according to gcc -std=c99 ) C99 doesn't support function overloading. The
Apparently there is a database postgres that is created by default on each postgresql
Apparently some vendors (like Telerik) are working on versions of their controls that do
Apparently libncurses...dylib is broken OS X 10.6.3 relative to Mutt, and perhaps other applications,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.