Estoy intentando dibujar una cadena con líneas nuevas (\ n) en una NSView de cacao con alineación central. Por ejemplo, si mi cadena es:Dibujar texto con alineación central en Cocoa View
NSString * str = @"this is a long line \n and \n this is also a long line";
me gustaría esto a aparecer algo como:
this is a long line
and
this is also a long line
Aquí está mi código dentro método NSView drawRect:
NSMutableParagraphStyle * paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
[paragraphStyle setAlignment:NSCenterTextAlignment];
NSDictionary * attributes = [NSDictionary dictionaryWithObject:paragraphStyle forKey:NSParagraphStyleAttributeName];
NSString * mystr = @"this is a long line \n and \n this is also a long line";
[mystr drawAtPoint:NSMakePoint(20, 20) withAttributes:attributes];
Todavía señala a la texto con alineación izquierda. ¿Qué está mal con este código?
¿Todavía estaría goteando paragraphStyle si estuviera usando Garbage Collection? – AmaltasCoder
@Amal Si está utilizando recolección de basura, no hay fugas. –