Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Blank space at top of UITextView in iOS 10

A text view is a scroll view. View controllers will add a content offset automatically to scroll views, as it is assumed they will want to scroll up behind the nav bar and status bar.

To prevent this, set the following property on the view controller containing the text view:

self.automaticallyAdjustsScrollViewInsets = NO

The current answer that IronManGill gave is not a good solution, because it is not based on an understanding of why the problem happens in the first place.

jrturton's answer is also not the cleanest way to solve it. You don't need to override. Keep it simple!

All you need is to set the following:

self.automaticallyAdjustsScrollViewInsets = NO;

in the viewDidLoad method.

Check out the docs: https://developer.apple.com/documentation/uikit/uiviewcontroller/1621372-automaticallyadjustsscrollviewin


In the Interface Builder,

  • Select the view controller which contains the UITextView.
  • Go to the attribute inspector.
  • Uncheck "Adjust Scroll View Insets."

This worked for me

textView.textContainerInset = UIEdgeInsetsZero;  
textView.textContainer.lineFragmentPadding = 0;

Go to Interface Builder:

  1. Select view controller that contains your text view
  2. uncheck Adjusts Scroll View Insets property

enter image description here