我正在尝试设置NSAttributedString
的行间距。问题是我无法为文本设置小的行间距。我可以设置领先的巨大值,如25或更多,但忽略小值。我正在尝试设置kCTParagraphStyleSpecifierMinimumLineHeight
或kCTParagraphStyleSpecifierMinimumLineSpacing
,但它无效。
这是我的代码,感谢任何帮助。
CGFloat leading = 50.0;
CGFloat minMineHeight = 1;
CTTextAlignment alignment = kCTCenterTextAlignment;
const CTParagraphStyleSetting styleSettings[] = {
{kCTParagraphStyleSpecifierMinimumLineSpacing, sizeof(CGFloat), &minMineHeight},
{kCTParagraphStyleSpecifierMinimumLineHeight, sizeof(CGFloat), &minMineHeight},
{kCTParagraphStyleSpecifierLineSpacing, sizeof(CGFloat), &leading},
{kCTParagraphStyleSpecifierParagraphSpacing, sizeof(CGFloat), &leading},
{kCTParagraphStyleSpecifierAlignment, sizeof(CTTextAlignment), &alignment}
};
CTParagraphStyleRef style = CTParagraphStyleCreate((const CTParagraphStyleSetting*) &styleSettings, 5);
[mutableAttributedString addAttribute:(NSString*)kCTParagraphStyleAttributeName value:(__bridge id)style range:NSMakeRange(0, [mutableAttributedString length])];
CFRelease(style);
return mutableAttributedString;
答案 0 :(得分:1)
您还需要设置最大行间距。