• 0
Votes
name
name Punditsdkoslkdosdkoskdo

What is “Constrain to margin” in Storyboard in Xcode 6

I am Working with autolayout and constraints and found there is a Constrain to margins option in XCode 6 which was not present in XCode 5 and is checked by default.

I created a test project then I added a UITableView on a ViewController with the frame set to the same size as view and added constraints

XCode 6 You can see here even though tableview has the same frame as view XCode suggests to add -16 as constraint whereas XCode 5 would suggest adding spacing 0.

With Constrain to margin checked

Now when you uncheck "Constrain to margin" option it behaves same as XCode 5 and would suggest adding 0 as constraint

With Constrain to margin UnChecked

Also, I found that once I add constraint with Constrain to margin checked, I am no longer able to open the storyboard file in XCode 5 so it's definitely something new in XCode 6

Hopefully, I am able to explain my question properly. I would like to understand what "Constrain to margin" actually does and when I should and should not use it. I do apologize if it's something very simple and obvious.

EDIT

I found something about layout margins in discussion here , I wonder if it's related to this.

In iOS 8 you now have the option to define your constrains relative to a predefined margin to the superview's bounds, instead of the superview's bounds themselves. Yes, it is totally related to the layout margins you pointed to in the docs. One advantage is that you may redefine your margins dynamically, or differently for each kind of device, and the layout will be updated correspondingly without modifying the constraints.

When to use it: when you want to take advantage of this new flexibility.

When to NOT use it: for any app targeted to run on iOS 7 or below.

  • 0
Reply Report