Change height limit programmatically

I want to change the height limit of a UITextView programmatically, so I set the limit as an output to my controller as follows:

@property (strong, nonatomic) IBOutlet NSLayoutConstraint *descriptionHeightConstraint; 

To change it, I do the following:

 self.descriptionHeightConstraint.constant = self.description.contentSize.height; 

This works if I do it in viewDidAppear , but the problem is that I see how the height changes after the view is displayed, which is not very convenient for the user, so I tried to do this in viewWillAppear , but did not work there, the height does not change . Calling setNeedsUpdateConstraints after changing the constraint did not work either.

Why does it work in viewDidAppear and not in viewWillAppear? Any workaround?

Thanks in advance!

+30
ios height autolayout constraints
Jan 05 '14 at 4:18
source share
1 answer

Try setting the constant in viewDidLayoutSubviews .

Please note that using the textSet property of the contentSize to set the height of the text view does not work in iOS 7. See https://stackoverflow.com/a/212632/

+27
Jan 05 '14 at 4:50
source share



All Articles