IOS: scrolling text view from bottom programmatically creates lots of spaces after text
I am trying to load the contents of a file in TextView
to viewDidLoad()
in ViewController
. I want the user to view the latest content loaded from the file, so I tried the solutions mentioned here .
let bottom = textView.contentSize.height - textView.bounds.size.height
textView.setContentOffset(CGPoint(x: 0, y: bottom), animated:true)
The text image will scroll down, but it will scroll down.
source to share
By updating the content offset, you are actually adding that much offset to the content of the scrollview. Here with
let bottom = textView.contentSize.height - textView.bounds.size.height textView.setContentOffset(CGPoint(x: 0, y: bottom), animated: true)
you add extra space at the bottom. Therefore, use the function to automatically scroll the content to the last line scrollRangeToVisible
. Like the top rated one, you mentioned in your question that you used to scroll the text to the last line.
source to share