nadim nadim - 1 year ago 119
Objective-C Question

iOS ScrollView setContentSize not Working

I am using Xcode 8, iOS 10. I have Create ScrollView from Storyboard. My Flow is

  • viewDidLoad method have Restcall, Which fetch Information from Server.

  • On Return, I parsed Response and based on that Create UIElements in Method and then add to one ParentView.

  • At last ParentView will be added to ScrollView.

[self.scrollView addSubview:parentView];
self.scrollView.frame = CGRectMake(0, 0, 320, parentView.frame.size.height);
[self.scrollView setContentSize:CGSizeMake(320, parentView.frame.size.height)];

When I print Scrollview height after this code, it shows "680" which is more than My View Height. I have tried with "viewDidLayoutSubviews" Method but still the ScrollView is not working.
Does anyone have any idea why It is not scrolling?

Answer Source

The problem in your code is that you are setting the scrollview height and contentSize height from parent view.

You should do as following :-

[self.scrollView addSubview:parentView];

self.scrollView.frame = CGRectMake(0, 0, 320, [UIScreen mainScreen].bounds.size.height);

[self.scrollView setContentSize:CGSizeMake(320, parentView.frame.size.height)];

Hope this will be helpfull

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download