Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
318 views
in Technique[技术] by (71.8m points)

ios - UIViewController Nested View To Screen Edge

I have a nested view inside my view controller and when i set the leading and trailing (to superview) constraints to 0, the subview spans between left and right edges of the superview leaving a margin on both sides. How do I remove this margin without adding a negative value in the constrains?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Assuming you're using Xcode 6...

There are two things to keep in mind when setting Auto Layout constraints regarding margins:

1. Adding new constraints

Xcode defaults new constraints to include margins. You'll find this on the 'Pin' menu - there's a checkbox that defaults to "Constrain to margins":

Constrain to margins checkbox under 'Pin' menu.

In the above screenshot, the left and right constraints both include margins. Unchecking this box will show the distance in points not including the margins:

Not including margins in the constraints.

2. Removing the margin calculation from an existing constraint.

You can adjust a constraint to not include the margin by selecting the constraint and accessing the Size Inspector (5th icon in right-hand panel, or Command+Option+5) and editing the portion that is relative to the margin. Access the dropdown and unselect the "Relative To Margin" option:

Remove the margin from the constraint.

Note that the constant value itself will stay the same, but the object will adjust and not longer take the margin into consideration.

Lastly, I haven't found a way to turn this behavior off.. I would prefer to not have constraints set against the margins by default, but as far as I am aware with Xcode 6.1.1 there isn't a way to change this behavior.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...