Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamic TextView with storyboards and auto layout

I have a view which has on top a UITextView then a series of other views. The idea is to resize the Text View on its content size and to move up all the other views.

I have set all the constraints in storyboard and if I change the height constraint value of my TextView from there, all the view updates fine.

On runtime I can resize the Text View frame to fit it's content size, but the rest of the view doesn't change. So I'm guessing I don't have to change the frame but only the height constraint.

Any suggestion on how is it possible to do this thing on runtime? How can I change the Height constraint value in code? Is there any way to "link" a constraint to the controller from storyboard?

Thanks for helping

like image 509
Dodgson86 Avatar asked Jul 22 '13 11:07

Dodgson86


1 Answers

Make an IBOutlet of height contraint from nib to your .h file. Lets name it textViewHeightConstraint

self.textViewHeightConstraint.constant = textView.contentSize.height
like image 131
Puneet Sharma Avatar answered Nov 02 '22 11:11

Puneet Sharma