why UIScrollView is leaving space from top in ios 6 and ios 7

IphoneObjective CIos6UiscrollviewIos7

Iphone Problem Overview


enter image description here

enter image description here

I have turned off Autolayout and viewcontroller is embedded in navigation controller. I am using Xcode 5, Storyboard.

I don't understand why is it leaving space from top. Actually in storyboard i have put my label exactly below navigation bar. But when i run it on simulator then it leaves space from top.

One of the hacky way to resolve this

-(void)viewWillLayoutSubviews
{
   self.scrollViewMain.frame = CGRectMake(0, -70, 320, 800);

   self.scrollViewMain.contentSize = CGSizeMake(320, 800);
}

But am i missing something very simple approach.

Iphone Solutions


Solution 1 - Iphone

In Xcode 5, in storyboard select your controller > in Attribute Inspector disable Adjust Scroll View Insets Also check if you have set any contentInset

Edit : I attached a pic

enter image description here

Solution 2 - Iphone

The fix is to implement the following line of code after in the viewDidLoad;

self.automaticallyAdjustsScrollViewInsets = NO;

Solution 3 - Iphone

Update for iOS 11

if #available(iOS 11.0, *) {
    scrollView.contentInsetAdjustmentBehavior = .never
} else {
    automaticallyAdjustsScrollViewInsets = false
}

Solution 4 - Iphone

Inspector: Select scrollView and set up Content Insets - never

enter image description here

Solution 5 - Iphone

> Go to main storyboard. Select view controller, see property "Adjust > Scroll view Insects" in attribute inspector. if you do not want top > spacing.then uncheck "Under Top Bars". if you don not want bottom > spacing.then uncheck "Under Bottom Bars". this kind of problem come > when we use scroll view related controllers. > > This is a feature for navigation and tab bar to adjust content in scroll view like controls.

Solution 6 - Iphone

For me in xcode 7 and Swift 2.x I was populating a UIScrollView with a for loop and had to set the contentInset to zero.

for image in images {
  self.scrollView.contentInset = UIEdgeInsetsZero
}

Solution 7 - Iphone

In your StoryBoard, select ContentInsets to never:

enter image description here

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
Questionbhavya kothariView Question on Stackoverflow
Solution 1 - IphoneRaheel SadiqView Answer on Stackoverflow
Solution 2 - IphoneAnooj VMView Answer on Stackoverflow
Solution 3 - IphonechengsamView Answer on Stackoverflow
Solution 4 - IphoneSvitlanaView Answer on Stackoverflow
Solution 5 - IphoneRavi KumarView Answer on Stackoverflow
Solution 6 - IphonewebjunkieView Answer on Stackoverflow
Solution 7 - IphoneAndoni Da SilvaView Answer on Stackoverflow