Saturday 15 June 2013

objective c - Check if text in UITextView went to new line due to word wrap -


How can I check that the text went to the next line due to the word op in UITextView ?

I currently have the code to know that the user enters a new line (from the keyboard).

  - (BOOL) textView: (UITextView *) textViewChangeTextInRange: (NSRange) Range replacement copy: (NSString *) text; {If ([text isqualToString: @ "\ n"]) {...} Return yes; }  

You can use ContentSize.Hight property to determine the UITextView How 'tall' is your textview then you can divide the number from the row, to find out the number of lines @Nacho provides this 4-digit code nifty line which does this:

  int numLines = textView.contentSize.height / textView.font.lineHeight;  

For more information, refer to this question:

Edit: You can do something like this: -textViewDidChange: To check a row change.

  Integer numbers = textual contents. Size / Hight / Text View Font LineHigh; If (numlines! = NumLinesIntextView) {numLinesInTextView = numLines; // numLinesInTextView is an example variable, then // which you need to do on line changes}  

No comments:

Post a Comment