How to set leading in CoreText?
You开发者_如何学编程 can get it with CTFontGetLeading(aCTFont), but how do you SET it?
Can anyone please explain?
Is there another way around this? Do you have to set the space between the lines manually, perhaps?
I found that when I was using multiple typefaces in a single paragraph, setting the min and max line height was not enough. I also had to set the line spacing to 0, otherwise the lines would have inconsistant leading. Here's my complete solution:
CGFloat lineHeight = 68.0f;
CGFloat lineSpacing = 0.0f;
CTParagraphStyleSetting setting[4] = {
{kCTParagraphStyleSpecifierMaximumLineHeight, sizeof(CGFloat), &lineHeight},
{kCTParagraphStyleSpecifierMinimumLineHeight, sizeof(CGFloat), &lineHeight},
{kCTParagraphStyleSpecifierMaximumLineSpacing, sizeof(CGFloat), &lineSpacing},
{kCTParagraphStyleSpecifierMinimumLineSpacing, sizeof(CGFloat), &lineSpacing}
};
CTParagraphStyleRef paragraphStyle = CTParagraphStyleCreate(setting, 4);
NSRange fullRange = NSMakeRange(0, [mutString length]);
[mutString addAttributes:[NSDictionary dictionaryWithObjectsAndKeys:(__bridge id)paragraphStyle,
(NSString*)kCTParagraphStyleAttributeName, nil]
range:fullRange];
CFRelease(paragraphStyle);
I got the solution here: http://www.iphonedevsdk.com/forum/iphone-sdk-development/59101-how-set-leading-coretext.html
Basically, just set the attribute kCTParagraphStyleSpecifierMinimumLineHeight. You can find it in CTParagraphStyle.h
精彩评论