nmock
nmock

Reputation: 1907

Creating autoresizing constraints

I am trying to use springs and struts to automatically resize content. What would the best way to create constaints like this, or is there a better way targeting iOS5+?

[View 1 - fixed height]

(10 pixel padding)

[View 2 - variable height scrollview / tableview, contains content]

Upvotes: 1

Views: 150

Answers (1)

rob mayoff
rob mayoff

Reputation: 385680

You are confusing the issue by referring to “autoresizing constraints”, because “autoresizing” usually refers to the old “springs and struts” system for updating view layout, and constraints are part of the new “autolayout” system (which requires iOS 6).

Anyway, you want to set view 1's autoresizingMask to UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin. This will keep its top, left and right edges pinned relative to its superview, and will keep its height fixed. If you're laying it out in Interface Builder, set it like this:

autoresizing for view 1

You want to set view 2's autoresizingMask to UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight. This will keep all of its edges pinned relative to its superview, and will let it get taller/shorter (and wider/narrower) in sync with changes to its superview's size. If you're laying it out in Interface Builder, set it like this:

autoresizing for view 2

It's up to you to lay them out with a 10 point space between them. If you do that, and set the autoresizing masks as I have described, then they will keep the 10 point space automatically when the superview changes size.

Upvotes: 1

Related Questions