如何在CoreText中设置行距?

发布于 2024-09-19 19:11:52 字数 108 浏览 4 评论 0原文

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

谁能解释一下吗?

还有其他办法解决这个问题吗?也许您必须手动设置行之间的间距?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

做个ˇ局外人 2024-09-26 19:11:53

我发现当我在一个段落中使用多种字体时,设置最小和最大行高是不够的。我还必须将行间距设置为 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);

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);
ペ泪落弦音 2024-09-26 19:11:53

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

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文