Note that there are some explanatory texts on larger screens.

plurals
  1. POResizing UIScrollView to fit its content… not working
    primarykey
    data
    text
    <p>I have an app that uses a UIScrollView to display content created by Interface Builder. I add a UITextView to it programmatically because its content is changeable and I want it to resize. This is done! The problem comes when resizing the UIScrollView to fit the new UITextView size. I just can't get it done.. I tried various methods including: </p> <p><code>CGRect contentRect = CGRectZero; for (UIView *view in self.scrollView.subviews) contentRect = CGRectUnion(contentRect, view.frame); self.scrollView.contentSize = contentRect.size;</code></p> <p>I think the problem is because it is built by Interface Builder but the UIScrollView contains other elements as well so I can't create it programmatically. I was hoping someone could help me on this.</p> <p><strong>UPDATE 1</strong>: I have both the UIView and the UIScrollView's heights set to 1024 from the Interface Builder.</p> <p><strong>UPDATE 2 (FIX)</strong>: I was able to fix this problem by issuing a timer at the end of the <code>viewDidLoad</code> method like so:</p> <p><code>[NSTimer scheduledTimerWithTimeInterval:0.00001 target:self selector:@selector(resizeScrollView) userInfo:nil repeats:NO]</code></p> <p>and then resizing it in the <code>resizeScrollView</code> method here:</p> <p><code>-(void)resizeScrollView { CGFloat scrollViewHeight = 0.0f; for (UIView* view in scrollView.subviews) { scrollViewHeight += view.frame.size.height; } [scrollView setContentSize:(CGSizeMake(320, scrollViewHeight-50))]; }</code></p> <p>Thanks for all the help! </p> <p><strong>NOTE</strong>: This solution was inspired by Maniac One's answer. Thanks!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload