darbid
darbid

Reputation: 2711

How to change a UIView size in iOS6 with autolayout on?

I understand the idea of the new auto layout technology in iOS6 is that you no longer need to set a frame, but you code by intent?

Following on from this at runtime if I change a UIView size by its frame any of its subviews currently are not moving and changing with the view.

I therefor have created an outlet for a constraint on the UIView and changed the constant of this constraint. This changes the size of the UIView and also all the subviews move appropriately.

Thus am I on the right track here? Is this how I am suppose to changed UIView sizes under auto layout?

Upvotes: 3

Views: 3300

Answers (1)

jrturton
jrturton

Reputation: 119242

You don't set frames. You update the relevant constraints instead (you will need references to these constraints, either as outlets or as properties you've kept around after creating the constraints in code).

As a simple example, if you've pinned a view's width, just alter the .constant property of the width constraint to set a new width on the view.

Here is an example view controller with a subview in it:

enter image description here

Create outlets to the Width and Height constraints and change them when you want to resize the view.

Upvotes: 9

Related Questions