Note that there are some explanatory texts on larger screens.

plurals
  1. POResizing UITextView Without Losing Constraints
    text
    copied!<p>I'm trying to figure out how to resize UITextView (and everything actually) without losing constraints. Basically, I'm trying to layout a page where most components can have variable sizes (like description). I tried doing it with a simple use case where I have a UITextView and a UIButton underneath. I want to make sure that the position of the button is relative to the bottom of the UITextView.</p> <pre><code>- (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; CGRect frame = self.textView.frame; int height = self.textView.contentSize.height; frame.size.height = height; self.textView.frame = frame; } </code></pre> <p>What I ended up with is UITextView overlapping with UIButton. After doing a bit of research, it seems that if I replace the frame, all constraints are gone also. I tried copying the constraints over, but of course the pointer is still pointing at the old frame so that didn't help at all.</p> <p>Is there a good way to solve a very dynamically laid out page? I'm trying to at least use interface builder rather than code everything.</p> <h2>EDITED</h2> <p>I tried updating the constraint as suggested, but that didn't actually resize the UITextView. Did I do it incorrectly? When I get the constant again, it's updated, but the height isn't changed visually. I did simplify my code by adding an IBOutlet for the constraint. Still no luck however.</p> <pre><code>int height = self.textView.contentSize.height; self.textViewHeightConstraint.constant = height; </code></pre> <h2>EDITED 2</h2> <p>I figured it out now. I had an extra constraint for the bottom and that was stopping me from actually resizing the UITextView.</p>
 

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