I draw the text using CTFramesetter, I have set kCTParagraphStyleSpecifierParagraphSpacing
, kCTParagraphStyleSpecifierLineSpacing
, kCTParagra
Damit, it's a bug. DTCoreText works around this by repositioning the baseline origins of those affected lines.
see http://www.cocoanetics.com/2012/02/radar-coretext-line-spacing-bug/
If you use NSMutableAttributeString
for text layout, you can set a CTRunDelegate
attribute to set the \n metrics to 0. For me this worked:
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);
and
static CGFloat lineBreakCallback( void* ref )
{
return 0;
}
EDIT: