andj
andj

Reputation: 3

iOS Autolayout: How to resize a view's height and update other view's frame related to it?

I am new to Auto Layout in iOS. My application has a Textview and a Button below the textview. The application need to update the textview's height and so the button always appear at the bottom of the textview. The views have enable Auto Layout. In my code, I do:

1.Change the frame of the green textview

self.testView.frame = FRAME(frame.origin.x, frame.origin.y, frame.size.width, frame.size.height + 10);

2.Call the view to update

   [self.view invalidateIntrinsicContentSize];

The problem is that the textview updates its height but it overlaps the button below it. Can anyone help me solve this problem?

Thanks in advance!

Upvotes: 0

Views: 522

Answers (1)

Vaibhav Saran
Vaibhav Saran

Reputation: 12908

Don't do it with code if you are >= iOS 6. Purely use autolayout. You need to set vertical spacing between textview and button.

enter image description here

This will show a constant space between your textview and button like this:

enter image description here

UPDATE: In your case:

UIButton's y axis = UITextView's height + UIButton's existing y + 10

Upvotes: 1

Related Questions