Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

auto scroll for UITextView using swift (IOS app)

I cant seem to find a right solution to autoscroll UITextView using Swift.

For my app I am receiving constant data from BT, and I am updating it on a UITextView. However, when the UITextView will reach the latest updated line, I would have to manually scroll.

What I'm trying to achieve is to keep the last added line to the UITextView visible. (using swift)

like image 741
Vatsal Patel Avatar asked Jan 26 '16 03:01

Vatsal Patel


1 Answers

This will scroll to the bottom of a UITextView, with an animation:

let range = NSMakeRange(textView.text.characters.count - 1, 0)
textView.scrollRangeToVisible(range)
like image 115
SwiftArchitect Avatar answered Oct 06 '22 23:10

SwiftArchitect