I\'m currently setting up a UIScrollView with the following structure
UIScrollView
--ContentView (UIView)
--ContainerView1 (UIView)
--UILabel1
--UILa
//use the below code to set the content size of a scroll view.
float newHeight=0.0f;
for(UIView *subViews in [scrollViewObj subviews])
{
if([subViews isKindOfClass:[UIView class]])
{
newHeight=newHeight+(subViews.frame.origin.x+subViews.frame.size.height);
}
}
NSLog(@"%f",newHeight);
[scrollView setContentSize:CGSizeMake(300, newHeight)];//change the width as you need
//i have added code for dynamically adding the subview heights
float newHeight=0.0f;
for(UIView *subViews in [scrollViewObj subviews])
{
if([subViews isKindOfClass:[UIView class]])
{
if([[subViews subviews] count]>0)
{
float heightOfSubviews=0.0f;
for(UIView *insideSubViews in [subViews subviews])
{
heightOfSubviews=heightOfSubviews+(insideSubViews.frame.origin.y+insideSubViews.frame.size.height);
}
NSLog(@"%f",heightOfSubviews);
[subViews setFrame:CGRectMake(subViews.frame.origin.x, subViews.frame.origin.y, subViews.frame.size.width, heightOfSubviews)];
}
}
}
UIView *viewLastObj=scrollViewObj.subviews.lastObject;
newHeight=viewLastObj.frame.origin.y+viewLastObj.frame.size.height;
NSLog(@"%f",newHeight);
[scrollViewObj setContentSize:CGSizeMake(300, newHeight)];