Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have a UIScrollView that includes some components, and one of these components is a UITextView, what I want is to let the UITextView dynamically expands with the UIScrollView, in fact I use autoLayout, so this code is not working:

    CGRect frame = self.detailTextView.frame;
    frame.size.height = self.detailTextView.contentSize.height;
    self.detailTextView.frame = frame;
    scroll.contentSize = CGSizeMake(scroll.contentSize.width,
                                    300 + self.detailTextView.frame.size.height);
    [self.detailTextView setFrame:frame];

What I want is to help me doing this with storyboard elements.

enter image description here

share|improve this question

1 Answer

Instead of setting the frame, drag one of the height constraints for your text view into your controller to create an outlet. Then in viewWillLayoutSubviews grab the contentSize and set the constant of your text view height constraint. That should accomplish what you're doing with the frame in your code above. Just be sure that your text view has constraints from all edges to your scroll view so that the scroll view can size itself properly.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.