Después de iOS 7, el enfoque styleString ya no funciona.
Hay dos nuevas alternativas disponibles.
En primer lugar, TextKit; un nuevo y poderoso motor de diseño. Para cambiar el espaciado de línea, ajuste delegado de controlador de distribución de la UITextView:
textView.layoutManager.delegate = self; // you'll need to declare you implement the NSLayoutManagerDelegate protocol
Entonces reemplazar este método delegado:
- (CGFloat)layoutManager:(NSLayoutManager *)layoutManager lineSpacingAfterGlyphAtIndex:(NSUInteger)glyphIndex withProposedLineFragmentRect:(CGRect)rect
{
return 20; // For really wide spacing; pick your own value
}
En segundo lugar, iOS 7 ahora soporta interlineado de NSParagraphStyle. Esto le da aún más control, p. sangría de primera línea y cálculo de un rect límite. Así que, alternativamente, ...
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
paragraphStyle.headIndent = 15; // <--- indention if you need it
paragraphStyle.firstLineHeadIndent = 15;
paragraphStyle.lineSpacing = 7; // <--- magic line spacing here!
NSDictionary *attrsDictionary =
@{ NSParagraphStyleAttributeName: paragraphStyle }; // <-- there are many more attrs, e.g NSFontAttributeName
self.textView.attributedText = [[NSAttributedString alloc] initWithString:@"Hello World over many lines!" attributes:attrsDictionary];
Fwiw, el viejo método contentInset para alinear el texto a lo largo del borde izquierdo de UITextView hay tampoco su uso bajo iOS7. En su lugar, para eliminar el margen:
textView.textContainer.lineFragmentPadding = 0;
@Suragch Ver la respuesta aceptada. –
Ah, lo siento, aceptó la nueva respuesta –