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.

+3


source to share


2 answers


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.

0


source


This minor change solved my problem:

let bottom = CGPoint(x: 0, y: textView.contentSize.height - textView.frame.size.height)
textView.setContentOffset(bottom, animated: false)

      



Posting your answer so that someone might find this helpful. Thank you all for your support.

0


source







All Articles