I'm using TTTAttributedLabel (which uses CoreText) instead of a UILabel to be able to bold certain parts. It works great but the text doesn't look the same. It looks like it's using a different font. I've set it to be the same font (Helvetica) but one is a CTFont and one is a UIFont. Why do they look different?
UIFont
for the UILabel: [UIFont systemFontOfSize:15]
CTFont
for CoreText: CTFontCreateWithName((__bridge CFStringRef)[UIFont systemFontOfSize:15].fontName, 15, NULL)
UILabel Screenshot:
CoreText Screenshot:
The 'p' and the 'o' in "promenade" is the easiest part to see the font doesn't look the same. Letters are more round in the CoreText version.
UILabel uses WebKit style text-rendering that takes shortcuts in accuracy to improve drawing performance. CoreText (originally from OS X) takes the opposite, render exactly and as perfectly as possible at the expense of performance.
For iOS apps, reserve CoreText for only the most visibly critical UI (such as a headline) and where you can potentially cache the rendered output.
I spent a while trying to solve this problem too, and I think I've got it. From what I've tested so far, your CoreText rendering will look identical to the rendering you see on UILabel, UITextView, etc, by setting kerning to zero:
NSNumber *kern = [NSNumber numberWithFloat:0];
NSRange full = NSMakeRange(0, [attributedText string].length);
[attributedText addAttribute:(id)kCTKernAttributeName value:kern range:full];
This is really strange behavior, and I can't say I know why it's happening, but this is what Apple seems to be doing. (It actually increased spacing in some places, like in between 'Te'.)
Tested on iOS 5.1.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With