我使用CTFramesetter绘制文本,我将kCTParagraphStyleSpecifierParagraphSpacing
,kCTParagraphStyleSpecifierLineSpacing
,kCTParagraphStyleSpecifierParagraphSpacingBefore
全部设置为0.0。
正如您在图片中看到的那样,段落的最后两行之间的空间比其他段落大得多。
此图片总共有15行,我粘贴了上升,下降,前导, origin.y 在下面,我们可以看到第5行和第10行的上升和下降比其他行更大,我找不到任何说明符来设置以避免这种奇怪的布局。
有什么想法吗?
1 ascent=20.639999, descent=3.360000, leading=0.720000, origin.y: 399.000000
2 ascent=20.639999, descent=3.360000, leading=0.720000, origin.y: 374.000000
3 ascent=20.639999, descent=3.360000, leading=0.720000, origin.y: 349.000000
4 ascent=20.639999, descent=3.360000, leading=0.720000, origin.y: 324.000000
5 ascent=25.722656, desecent=13.699219, leading=0.720000, origin.y: 294.000000
6 ascent=20.639999, descent=3.360000, leading=0.720000, origin.y: 258.000000
7 ascent=20.639999, descent=3.360000, leading=0.720000, origin.y: 233.000000
8 ascent=20.639999, descent=3.360000, leading=0.720000, origin.y: 208.000000
9 ascent=20.639999, descent=3.360000, leading=0.720000, origin.y: 183.000000
10 ascent=25.722656, descent=13.699219, leading=0.720000, origin.y: 153.000000
11 ascent=20.639999, descent=3.360000, leading=0.720000, origin.y: 117.000000
12 ascent=20.639999, descent=3.360000, leading=0.720000, origin.y: 92.000000
13 ascent=20.639999, descent=3.360000, leading=0.720000, origin.y: 67.000000
14 ascent=20.639999, descent=3.360000, leading=0.720000, origin.y: 42.000000
15 ascent=20.639999, descent=3.360000, leading=0.720000, origin.y: 17.000000
答案 0 :(得分:1)
如果您使用NSMutableAttributeString
进行文字布局,则可以设置CTRunDelegate
属性以将\ n指标设置为0.对我而言,这有效:
CTRunDelegateCallbacks callbacks;
callbacks.version = kCTRunDelegateVersion1;
callbacks.getAscent = lineBreakCallback;
callbacks.getDescent = lineBreakCallback;
callbacks.getWidth = lineBreakCallback;
CTFontRef fontRef = CTFontCreateWithName((CFStringRef)@"System", 1.0f, NULL);
CTRunDelegateRef delegate = CTRunDelegateCreate(&callbacks, NULL); //3
NSDictionary *attrDictionaryDelegate = [NSDictionary dictionaryWithObjectsAndKeys:
//set the delegate
(__bridge id)delegate, (NSString*)kCTRunDelegateAttributeName,
(__bridge id)fontRef, kCTFontAttributeName,
nil];
stringLength++;
[attString appendAttributedString:[[NSAttributedString alloc] initWithString:@"\n" attributes:attrDictionaryDelegate]];
CFRelease(delegate);
CFRelease(fontRef);
和
static CGFloat lineBreakCallback( void* ref )
{
return 0;
}
编辑:
答案 1 :(得分:0)
该死,这是一个错误。 DTCoreText通过重新定位受影响线的基线来源来解决这个问题。
请参阅http://www.cocoanetics.com/2012/02/radar-coretext-line-spacing-bug/