Answer the question
In order to leave comments, you need to log in
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 < numberOfGlyphs; numberOfLines++){<br/>
[layoutManager lineFragmentRectForGlyphAtIndex:index effectiveRange:&lineRange];<br/>
index = NSMaxRange(lineRange);<br/>
}<br/>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question