Scrolling UITextView when adding a line in Swift 5

I am using a UITextView to output and display multiple limes of program status. I would like to have the text scroll up when a line is added at the end. The text is all generated internally, and the user has no control over the text box. This seems to be a fundamental function for a scrolling text box, but I can't seem to get the UITextView to do it. What could I be doing wrong?

Accepted Reply

Just have to add:

let range = NSMakeRange(textView.text.characters.count - 1, 0)
textView.scrollRangeToVisible(range)

after text has been appended.


See https://stackoverflow.com/questions/35006738/auto-scroll-for-uitextview-using-swift-ios-app

Replies

Just have to add:

let range = NSMakeRange(textView.text.characters.count - 1, 0)
textView.scrollRangeToVisible(range)

after text has been appended.


See https://stackoverflow.com/questions/35006738/auto-scroll-for-uitextview-using-swift-ios-app