B
B
buddax22011-03-09 13:55:34
Cocoa
buddax2, 2011-03-09 13:55:34

Limit on the number of input lines in NSTextView?

There is a text input field NSTextView. What you need:
1. limit the number of characters entered to 150 as much as possible;
2. limit the maximum number of lines to 4.
The first is quite simple. But on the second point I have a problem. I can count the number of lines of text in a field

NSLayoutManager *layoutManager = [NSTextView layoutManager];<br/>
NSUInteger numberOfLines, index, numberOfGlyphs = [layoutManager numberOfGlyphs];<br/>
NSRange lineRange;<br/>
<br/>
for (numberOfLines = 0, index = 0; index &lt; numberOfGlyphs; numberOfLines++){<br/>
 [layoutManager lineFragmentRectForGlyphAtIndex:index effectiveRange:&lineRange];<br/>
 index = NSMaxRange(lineRange);<br/>
}<br/>

But how to cut it to the required number of lines?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question