jwerre jwerre - 1 year ago 105
Objective-C Question

How I auto size a UIScrollView to fit the content

Is there a way to make a

auto-adjust to the height (or width) of the content it's scrolling?

Something like:

[scrollView setContentSize:(CGSizeMake(320, content.height))];

Answer Source

The best method I've ever come across to update the content size of a UIScrollView based on its contained subviews:

CGRect contentRect = CGRectZero;
for (UIView *view in self.scrollView.subviews) {
    contentRect = CGRectUnion(contentRect, view.frame);
self.scrollView.contentSize = contentRect.size;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download