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
extension NSLayoutManager {
var numberOfLines: Int {
guard let textStorage = textStorage else { return 0 }
var count = 0
enumerateLineFragments(forGlyphRange: NSMakeRange(0, numberOfGlyphs)) { _, _, _, _, _ in
count += 1
}
return count
}
}
Get number of lines in textView:
let numberOfLines = textView.layoutManager.numberOfLines