Search code examples
iosswiftcocoa-touchuitextview

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)


Solution

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

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