Pregunta

META:

Estoy intentando usar NSATTributedStrings (junto con nstextTabs) para crear el siguiente diseño:

[ Title           # ]  <-- Useable in NSTableViews, NSMenuItems, etc.
[ Another Title   # ]
[ T3              # ]

Intento de solución:

El código que estoy intentando es:

NSMutableParagraphStyle *tabStyle = [[NSMutableParagraphStyle alloc] init];
[tabStyle setTabStops: [NSArray array]];
[tabStyle addTabStop: [[NSTextTab alloc] initWithType: NSRightTabStopType location: 200.0]];
[attrString appendAttributedString: [[NSMutableAttributedString alloc] initWithString: @"\t"]];
[attrString addAttribute: NSParagraphStyleAttributeName value: tabStyle range: NSMakeRange(0, [attrString length])];
[attrString appendAttributedString: [[NSMutableAttributedString alloc] initWithString: @"1"]];

Dónde attrString es un nsmutableAttributeString, actualmente establecido en el "título".

Sin embargo, el uso de este código (que supongo que produciría la salida deseada) produce lo siguiente:

Screenshot - NSTextTabs

MÁS INFORMACIÓN:

Cuando elimino las referencias a nstextTabs, como así:

[attrString appendAttributedString: [[NSMutableAttributedString alloc] initWithString: @"\t"]];
[attrString appendAttributedString: [[NSMutableAttributedString alloc] initWithString: @"1"]];

Obtengo el resultado esperado de pestañas desiguales.

Screenshot - No NSTexTabs

LÍNEA DE FONDO:

¿Por qué el NSATTributedString está ignorando el NsparagraphStyle/NStextTabs?

¿Qué puedo hacer para arreglar esto?

¿Fue útil?

Solución

Encontré el problema, haciendo un NSTEXTVIEW en IB y colocando el AttributedString en él.

enter image description here

Aparentemente, el diseño debe ser "pergaminos" (fue "truncado") para producir el efecto deseado.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top