我正在尝试设置NSAttributedString
. 问题是我不能为文本设置一个小的行距。我可以为前导设置很大的值,例如 25 或更多,但忽略较小的值。我正在尝试设置kCTParagraphStyleSpecifierMinimumLineHeight
or 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;