После iOS 7 подход styleString больше не работает.
Доступны две новые альтернативы.
Во-первых, TextKit;мощный новый макет двигателя.Чтобы изменить межстрочный интервал, установите делегат менеджера макета UITextView:
textView.layoutManager.delegate = self; // you'll need to declare you implement the NSLayoutManagerDelegate protocol
Затем переопределите этот метод делегата:
- (CGFloat)layoutManager:(NSLayoutManager *)layoutManager lineSpacingAfterGlyphAtIndex:(NSUInteger)glyphIndex withProposedLineFragmentRect:(CGRect)rect
{
return 20; // For really wide spacing; pick your own value
}
Во-вторых, iOS 7 теперь поддерживает lineSpacing в NSParagraphStyle.Это дает еще больший контроль, например, отступ первой строки и вычисление ограничивающего прямоугольника.Так что альтернативно ...
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, старый метод contentInset для выравнивания текста по левому краю UITextView также не используется в iOS7.Вместо этого удалите поля:
textView.textContainer.lineFragmentPadding = 0;