Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save chaitanyaSoni96/313d2b05a684de56e91ee80b6150cf77 to your computer and use it in GitHub Desktop.
Save chaitanyaSoni96/313d2b05a684de56e91ee80b6150cf77 to your computer and use it in GitHub Desktop.
Set Scroll View Content Size Dynamically
-(void)setContentSizeForScrollView{
NSArray* scrollViewSubViews = [self.rootScrollView subviews];
CGFloat scrollViewHeight = 0;
for (UIView* views in scrollViewSubViews) {
scrollViewHeight += views.frame.size.height;
}
[self.rootScrollView setContentSize:CGSizeMake(self.view.frame.size.width, scrollViewHeight)];
}
-(void)setScrollViewContentSize{
CGRect contentRect = CGRectZero;
for (UIView *view in self.scrollView.subviews) {
contentRect = CGRectUnion(contentRect, view.frame);
}
self.scrollView.contentSize = contentRect.size;
}
func setScrollViewContentSize() {
var contentRect = CGRect.zero
self.scrollView.subviews.forEach { (view) in
contentRect = contentRect.union(view.frame)
}
self.scrollView.contentSize = contentRect.size
}
var contentRect = CGRect.zero
for view in mainScrollView.subviews {
contentRect = contentRect.union(view.frame)
}
scrollView.contentSize = contentRect.size
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment