Search code examples
iosswiftuiscrollviewinsets

Top Empty Space Added in UIScrollView


I created an ScrollView Programatically using swift I added a UIView in it After adding these both to view it shows Empty Space on Top of the ScrollView How can i remove that, i searched in google and i found several and i tried them

self.edgesForExtendedLayout = UIRectEdge.None;
self.extendedLayoutIncludesOpaqueBars = true;
self.automaticallyAdjustsScrollViewInsets = false;

and

let insets = UIEdgeInsetsMake(self.topLayoutGuide.length, 0.0, self.bottomLayoutGuide.length, 0.0);
scrollContainer.contentInset = insets;

please suggest


Solution

  • The issue is caused by the navigation bar and bottom tab bar. So your inset should be like this:

    let insets = UIEdgeInsetsMake(0, 0.0, 0.0, 0.0);
    

    If you are using storyboard and auto layout, then you need to following the setting below:

    enter image description here