talanb
talanb

Reputation: 994

Modifying a storyboard that is already laid out with auto layout

I am working through the CS193P Stanford iOS course and I am struggling with auto layout. I have laid out my calculator ViewController and set up all of my constraints. Now I need to add additional UI elements and I'm not sure how to got about it. In the storyboard editor in Xcode my existing UI elements are taking up the entire view controller. Do I need to just delete all of my existing constraints, move the UI elements around to their new positions and recreate all of the constraints or can this be done incrementally without having to recreate all of the constraints.

Upvotes: 0

Views: 38

Answers (1)

Ken Thomases
Ken Thomases

Reputation: 90611

You can move and resize the controls with the constraints still in place. Xcode will note that there are misplaced views, but that will go away after you adjust the constraints.

Depending on exactly what you want to do, you can tell Xcode to adjust the constraints to match the new layout on the canvas. However, if you need to interpose a new control between things that were previously spaced relative to each other, you should delete that constraint and add two new ones. That is, if you had something like (in visual format language) [view1]-[view2] and you want to put another view between those to get [view1]-[view3]-[view2], you will want to remove the constraint between view1 and view2 and create two new constraints, one between view1 and view3 and another between view3 and view2.

Upvotes: 1

Related Questions