OMH
OMH

Reputation: 785

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?

Upvotes: 0

Views: 1917

Answers (2)

wdlindmeier
wdlindmeier

Reputation: 41

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);

Upvotes: 2

OMH
OMH

Reputation: 785

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

Upvotes: 0

Related Questions