简体   繁体   中英

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?

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:

在此输入图像描述

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM