Reputation: 773
I have the following lines of code:
textView.textContainer.maximumNumberOfLines = 10;
textView.textContainer.lineBreakMode = NSLineBreakByTruncatingHead;
[textView setText:@"1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11"];
No matter what I set the lineBreakMode to, the output always excludes the 11, but includes the 1. I need to truncate the start of the string, not the end. Any ideas on why this isn't working?
Upvotes: 0
Views: 147
Reputation: 57149
That’s not what the line break mode does. If an individual line is wider than will fit in the text view, that mode should cause it to get truncated at the head rather than wrapping to an additional line, but it won’t cause the text view to change which lines it displays.
To get the effect you’re after, you’ll have to modify the string yourself. If it’s formatted the way your test string is (with explicit newlines) that’s relatively easy—-rangeOfString:options:range:
will let you search backwards along the string until you find the start of the Nth line you want to keep—but if you’re relying on word wrapping, then you’ll have to use -boundingRectWithSize:options:attributes:
and keep chopping words off the beginning until it fits within the size you need.
Upvotes: 1