My code below scrolls all the way to the bottom of the text field. How can I do the reverse of this and have the code function to scroll to the very beginning of the text field?
let bottom = NSMakeRange(theTextView.text.characters.count - 1, 1)
theTextView.scrollRangeToVisible(bottom)
The most obvious solution is to set the
location
parameter ofNSMakeRange
to 0 instead oftheTextView.text.characters.count - 1
.A better way is to note that
UITextView
extendsUIScrollView
. So you can set thecontentOffset
:If your want to animate the scrolling, use: