ios - Text in UITextView Auto-Scrolled to Bottom -


i have believe standard uitextview in viewcontroller has substantial amount of text in it, enough not of can fit on screen. happen when view loaded, user can start reading @ top of text , scroll down page progress through text. makes sense, right? want not unrealistic.

the problem when view loads, text in uitextview scrolled way down bottom. have scoured , there number of similar posts none of solutions therein resolving problem. here code in view controller:

import uikit  class welcometextvc: uiviewcontroller {      var textstring: string = ""      @iboutlet weak var welcometext: uitextview!      override func viewdidload() {         super.viewdidload()          self.navigationcontroller?.navigationbar.translucent = false          self.welcometext.text = textstring         self.welcometext.scrollrangetovisible(nsmakerange(0, 0))     }      override func viewwillappear(animated: bool) {         super.viewwillappear(true)          self.welcometext.scrollrangetovisible(nsmakerange(0, 0))         welcometext.setcontentoffset(cgpointmake(0, -self.welcometext.contentinset.top), animated: true)     }      override func didreceivememorywarning() {         super.didreceivememorywarning()         // dispose of resources can recreated.     }  } 

i have tried of standard solutions no avail. 1 common suggestion have not tried "uncheck adjust scroll view insets in attributes inspector". reason have not tried because cannot locate fabled check box.

what need make text start out aligned top?

there's couple ways know of. both ways implemented programmatically through viewdidlayoutsubviews() method in view controller. after call super.viewdidlayoutsubviews(), add:

mytextview.scrollrangetovisible(nsmakerange(0, 1)) 

this automatically scroll textview first character in textview. might add unwanted animation when view appears. second way adding:

mytextview.setcontentoffset(cgpoint.zero, animated: false) 

this scrolls uitextview point 0 (the beginning) , gives control on whether want animated or not.


Comments

Popular posts from this blog

matlab - error with cyclic autocorrelation function -

django - (fields.E300) Field defines a relation with model 'AbstractEmailUser' which is either not installed, or is abstract -

c# - What is a good .Net RefEdit control to use with ExcelDna? -