Last active
July 1, 2020 07:02
-
-
Save chaitanyaSoni96/313d2b05a684de56e91ee80b6150cf77 to your computer and use it in GitHub Desktop.
Set Scroll View Content Size Dynamically
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(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