I'm trying to set the line spacing of NSAttributedString. The problem is that I can't set a small linespacing for the text. I can set huge values for the leading, like 25 or more, but small values are ignored. I'm trying to set kCTParagraphStyleSpecifierMinimumLineHeight or kCTParagraphStyleSpecifierMinimumLineSpacing, but it is not working.
This is my code, any help is appreciated.
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;
You also need to set the maximum line spacing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With