Found a solution here ScrollView ContentSize, you will be able to find the sizes of the subviews and find the combined content size and also options to say whether subviews are arranged horizontally or vertically.
Here is the code from the link above :
@interface UIScrollView(auto_size)
- (void) adjustHeightForCurrentSubviews: (int) verticalPadding;
- (void) adjustWidthForCurrentSubviews: (int) horizontalPadding;
- (void) adjustWidth: (bool) changeWidth andHeight: (bool) changeHeight withHorizontalPadding: (int) horizontalPadding andVerticalPadding: (int) verticalPadding;
@end
@implementation UIScrollView(auto_size)
- (void) adjustWidth: (bool) changeWidth andHeight: (bool) changeHeight withHorizontalPadding: (int) horizontalPadding andVerticalPadding: (int) verticalPadding {
float contentWidth = horizontalPadding;
float contentHeight = verticalPadding;
for (UIView* subview in self.subviews) {
[subview sizeToFit];
contentWidth += subview.frame.size.width;
contentHeight += subview.frame.size.height;
}
contentWidth = changeWidth ? contentWidth : self.superview.frame.size.width;
contentHeight = changeHeight ? contentHeight : self.superview.frame.size.height;
NSLog(@"Adjusting ScrollView size to %fx%f, verticalPadding=%d, horizontalPadding=%d", contentWidth, contentHeight, verticalPadding, horizontalPadding);
self.contentSize = CGSizeMake(contentWidth, contentHeight);
}
- (void) adjustHeightForCurrentSubviews: (int) verticalPadding {
[self adjustWidth:NO andHeight:YES withHorizontalPadding:0 andVerticalPadding:verticalPadding];
}
- (void) adjustWidthForCurrentSubviews: (int) horizontalPadding {
[self adjustWidth:YES andHeight:NO withHorizontalPadding:horizontalPadding andVerticalPadding:0];
}
@end
Also make sure to have a look at the comments on the blog page as an alternative solution is provided.
-anoop