2011-04-14 15 views
5

Al aplicar el estilo kCTParagraphStyleSpecifierParagraphSpacing, no tiene efecto visual en el texto renderizado. Los otros atributos, como el espaciado entre líneas y la alineación del texto, funcionan perfectamente. ¿Qué podría estar haciendo mal?NSAttributedString kCTParagraphStyleSpecifierParagraphSpacing no tiene ningún efecto

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), &paragraphSpacingFloat }, 
    { kCTParagraphStyleSpecifierParagraphSpacingBefore, sizeof(CGFloat), &paragraphSpacingBeforeFloat }, 
    { 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); 

pagaré el texto utilizando

CTFrameSetter frameSetter = CTFramesetterCreateWithAttributedString((CFAttributedStringRef)attr); 
CTFrameRef frame = CTFramesetterCreateFrame(frameSetter, CFRangeMake([[attr string] length], 0), the_drawing_cgrect, NULL); 
CTFrameDraw(frame, context); 

Respuesta

4

¿Estás seguro de que tu cuerda tiene separadores de párrafo? kCTParagraphStyleSpecifierParagraphSpacing no funciona en líneas nuevas. Requiere real \ u2029.

probar este código para reemplazar todos los saltos de línea con separadores de párrafos:

NSArray *paragraphs = [string componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]]; 
NSString *text = [items componentsJoinedByString:@"\u2029"]; 
+0

Interesante! Estoy bastante seguro de que este fue el problema, ¡gracias! No he tocado este problema desde entonces, ya que lo resolví de una manera diferente. –

+0

@blago - ¿Cómo lo resolviste blago? –

Cuestiones relacionadas