How to Read Number of lines in UITextView

前端 未结 4 2101
野性不改
野性不改 2020-12-14 16:57

I am using UITextView In my View , I have requirement to count number of line contained by textview am using following function to read \'\\n\' . H

4条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-14 17:37

    Just for reference...

    Another way you can get the number of lines and also the content, is splitting the lines in an array using the same method mentioned on the answer edit by BoltClock.

    NSArray *rows = [textView.text componentsSeparatedByString:@"\n"];
    

    You can iterate through the array to get the content of each line and you can use the [rows count] to get the exact number of rows.

    One thing to keep in mind is that empty lines will be counted as well.

提交回复
热议问题