4

I use view controller with embedded in navigation controller.

In this view I added scroll view and then content view inside scroll view

I added constrains for scroll view - zero for top, bottom, leading, and trailing. And the same for content view - zero for top, bottom, leading, and trailing. And I added width and height for content view the same as main view.

Inside content view I need to add different content (labels, text fields, buttons) - this will be settings screen with vertical scroll.

Now I see that content is always shifted down a bit (the same value as menu height)

How to make to located vertically on top?

And how to put all the content in the content view that should be vertically long and scrollable vertically?

enter image description here

enter image description here

enter image description here

Bogdan Laukhin
  • 1,454
  • 2
  • 17
  • 26

6 Answers6

11

I think you forget to remove tick -> Adjust scrollview insects .

enter image description here

Badal Shah
  • 7,541
  • 2
  • 30
  • 65
2

Just add this line to the viewDidload method of your ViewController.

self.automaticallyAdjustsScrollViewInsets = NO;
Kunal Kumar
  • 1,722
  • 1
  • 17
  • 32
0

Check you attribute inspector setting in Storyboard.Uncheck

adjustScrollViewInsets

from viewcontroller storyboard.Viewcontroller Storyboard settings.

enter image description here

Sheereen S
  • 1,292
  • 10
  • 18
0

Go to storyboard and select the appropriate viewcontroller and Uncheck AutomaticallyadjustScrollviewInsets.

Or

Go to viewdidload self.automaticallyAdjustsScrollViewInsets=NO;

Arun
  • 624
  • 4
  • 18
0

Go to your viewcontroller viewDidLoad method put following code.

self.automaticallyAdjustsScrollViewInsets=NO;
Nimit Parekh
  • 16,776
  • 8
  • 50
  • 72
0

In iOS 11, automaticallyAdjustsScrollViewInsets is deprecated and adjusting UIScrollView's contentInsetAdjustmentBehavior is recommended instead.

This worked for me pretty well (Swift):

scrollView.contentInsetAdjustmentBehavior = .automatic
poroia
  • 45
  • 1
  • 10