Reputation: 395
I am having the same issue as others have and already posted in the forum. The text inside my texview starts from the middle and not from the top. I already tried some code that is provided in other posts but i have the same result. These are examples of what i used so far.
self.maintext.scrollRangeToVisible(NSMakeRange(0, 0))
self.maintext.contentInset = UIEdgeInsetsMake(2.0,1.0,0,0.0);
self.automaticallyAdjustsScrollViewInsets = false
I tried them all by once and all together. The only result that i got was that my text was starting a little upper than without the code. Why is this happening? I tried also to change from the interface builder the view mode to TOP but still nothing. I am loading the text from an rtf file. Could anyone give me an explanation of what is happening? Thank you.
Upvotes: 4
Views: 1689
Reputation: 479
Try this one: :)
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
namesDescText.setContentOffset(CGPoint.zero, animated: false)
Upvotes: 0
Reputation: 106
In the ViewController containing the UITextField, add this:
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
textView.setContentOffset(CGPoint.zero, animated: false)
}
Upvotes: 6