Inspired by this answer.
It appears, that you need to calculate word wrapping by yourself.
Here is a simple example:
@interface UITextView (Lines)
- (NSArray*) textLines;
@end
@implementation UITextView (Lines)
- (NSArray*) textLines{
NSMutableArray *result = @[].mutableCopy;
NSArray *input = [self.text componentsSeparatedByString:@" "];
NSDictionary *attributes = @{NSFontAttributeName:self.font};
CGFloat maxWidth = self.frame.size.width - self.textContainer.lineFragmentPadding*2;
NSMutableString *currentLine = @"".mutableCopy;
for (NSString *component in input) {
NSString *componentCheck = [NSString stringWithFormat:@" %@",component];
CGSize currentSize = [currentLine sizeWithAttributes:attributes];
CGSize componentSize = [componentCheck sizeWithAttributes:attributes];
if (currentSize.width + componentSize.width < maxWidth) {
[currentLine appendString:componentCheck];
}else{
[result addObject:currentLine];
currentLine = component.mutableCopy;
}
}
return result;
}
@end