Blank space at top of UITextView in iOS 10

IosIphoneXcodeCocoa TouchUitextfield

Ios Problem Overview


I have UITextView with some text in it. Everything was fine with iOS 6 but now with iOS 7 it leaves the blank space on top and then place the text below the middle of the textview.enter image description here

I didn't set any contentOffSet. Please Help!

Ios Solutions


Solution 1 - Ios

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

Solution 2 - Ios

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

Solution 3 - Ios

In the Interface Builder,

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

Solution 4 - Ios

This worked for me

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

Solution 5 - Ios

Go to Interface Builder:

  1. Select view controller that contains your text view

  2. uncheck Adjusts Scroll View Insets property

enter image description here

Solution 6 - Ios

I really wonder if this is a real feature… This 64 point automatic inset is only added when the UIScrollView or UITextView as the greater deepness of all subviews of the view controller's view. For example, if you add a view behind (here I'm talking about z-buffer, not view imbrication) the scroll view, this 64 point inset is not automatically added.

For example, this one adds the inset:

enter image description here

In this case, the inset is not added:

enter image description here

This really seem strange to me… Why would the OS look at the view's deepness to decide whether it should extend the view?

Solution 7 - Ios

You can delete the blank space on top of your UITextView by adding:

yourTextView.textContainerInset = UIEdgeInsetsZero;

Solution 8 - Ios

On swift (Xcode 6)

 self.automaticallyAdjustsScrollViewInsets = false

Solution 9 - Ios

I resolved this issue by setting content offset to a negative value. Here is Swift code.

yourTextView.setContentOffset(CGPoint(x: 0, y: -150), animated: true)

Solution 10 - Ios

What you have to understand is that this relates to the navigation bar:

  • If your content goes under the navigation bar, you want the view controller to automatically adjust the scroll view insets (default).
  • If your content does not go under the navigation bar (you probably used the top layout guide for the top space constraint), you can disable the automatic scroll view inset adjustment like mentioned in most of the other replies.

Solution 11 - Ios

I tried the following trick, it worked.

- (void)viewDidLoad{
   self.textView.scrollEnabled = NO;  
}       
- (void)viewDidAppear:(BOOL)animated {
   [super viewDidAppear:animated];
   self.textView.scrollEnabled = YES;
}

Solution 12 - Ios

Solution for Swift 4:

textView.textContainerInset = UIEdgeInsets.zero

Solution 13 - Ios

This is an unprofessional solution, I'm sure... But just putting a blank label behind the textview solves the problem.

Solution 14 - Ios

This just worked for me (available from iOS 7)

[<#your UITextViewInstance#> setTextContainerInset:UIEdgeInsetsZero];

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAli SufyanView Question on Stackoverflow
Solution 1 - IosjrturtonView Answer on Stackoverflow
Solution 2 - IosDumokoView Answer on Stackoverflow
Solution 3 - Iosuser2268026View Answer on Stackoverflow
Solution 4 - IosRavi BihaniView Answer on Stackoverflow
Solution 5 - IosAamirView Answer on Stackoverflow
Solution 6 - IosMonsieurDartView Answer on Stackoverflow
Solution 7 - IoslberyoukView Answer on Stackoverflow
Solution 8 - IosClaudio Barrozo PradoView Answer on Stackoverflow
Solution 9 - IosSaqib OmerView Answer on Stackoverflow
Solution 10 - IosCodeStageView Answer on Stackoverflow
Solution 11 - IoscasillasView Answer on Stackoverflow
Solution 12 - IosKostas TsoleridisView Answer on Stackoverflow
Solution 13 - IosTerenceView Answer on Stackoverflow
Solution 14 - IosRyanTCBView Answer on Stackoverflow