應用kCTParagraphStyleSpecifierParagraphSpacing樣式時,它對渲染文本沒有視覺效果。其他屬性,如行間距和文本對齊完美。我可能做錯了什麼?NSAttributedString kCTParagraphStyleSpecifierParagraphSpacing無效
CTTextAlignment theAlignment = kCTRightTextAlignment;
CGFloat paragraphSpacingFloat = 150.0;
CGFloat paragraphSpacingBeforeFloat = 150.0;
CGFloat lineSpacing = CTFontGetLeading(baseFont)*5.0;
CFIndex theNumberOfSettings = 4;
CTParagraphStyleSetting theSettings[4] = {
{ kCTParagraphStyleSpecifierParagraphSpacing, sizeof(CGFloat), ¶graphSpacingFloat },
{ kCTParagraphStyleSpecifierParagraphSpacingBefore, sizeof(CGFloat), ¶graphSpacingBeforeFloat },
{ kCTParagraphStyleSpecifierAlignment, sizeof(CTTextAlignment), &theAlignment },
{ kCTParagraphStyleSpecifierLineSpacing, sizeof(CGFloat), &lineSpacing }
};
CTParagraphStyleRef theParagraphRef = CTParagraphStyleCreate(theSettings, theNumberOfSettings);
[attr addAttribute:(id)kCTParagraphStyleAttributeName value:(id)theParagraphRef range:r];
[attr addAttribute:(id)kCTFontAttributeName value:(id)baseFont range:r];
CFRelease(theParagraphRef);
我渲染使用
CTFrameSetter frameSetter = CTFramesetterCreateWithAttributedString((CFAttributedStringRef)attr);
CTFrameRef frame = CTFramesetterCreateFrame(frameSetter, CFRangeMake([[attr string] length], 0), the_drawing_cgrect, NULL);
CTFrameDraw(frame, context);
有趣!我很確定這是問題,謝謝!從那以後我就沒有觸及過這個問題,因爲我以不同的方式解決了這個問題。 – 2011-11-26 09:47:29
@blago - 你是怎麼解決它的? – 2012-08-17 21:45:38