如何在CoreText中设置领先?

时间:2010-09-13 06:31:48

标签: iphone ipad core-text

您可以使用CTFontGetLeading(aCTFont)获取它,但是如何设置它?

有人可以解释一下吗?

还有另一种解决方法吗?您是否必须手动设置行之间的空间?

2 个答案:

答案 0 :(得分:2)

我发现当我在一个段落中使用多个字体时,设置最小和最大行高度是不够的。我还必须将行间距设置为0,否则行将具有不一致的行距。这是我的完整解决方案:

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

答案 1 :(得分:0)

我在这里得到了解决方案: http://www.iphonedevsdk.com/forum/iphone-sdk-development/59101-how-set-leading-coretext.html

基本上,只需设置属性kCTParagraphStyleSpecifierMinimumLineHeight。你可以在CTParagraphStyle.h中找到它