Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode 6 set default values for layout margins or disable them

This new feature of Xcode 6 is kinda annoying. Most of the time I don't need to set offset relative to margins, and if I do I may want to use values other than default 16. Is there a way to change default value or totally disable margins for my project (or for all projects in my Xcode)?

like image 364
Spail Avatar asked Sep 18 '14 14:09

Spail


People also ask

What is constrain to margin in Xcode?

Basically if the layout margins are 8,8,8,8 (the default), a constraint with 0 leading space to container margin will have an x position of 8. Note that this is only available on iOS8 or later.

What does constrain to margins do?

By unchecking "constraints to margin", you are adding constraints, meaning your interface will react correctly to changes in size or orientation.

What is layout margins?

Layout margins provide a visual buffer between a view's content and any content outside of the view's bounds. The layout margins consist of inset values for each edge (top, bottom, leading, and trailing) of the view.


2 Answers

You cannot "turn them off" because they're built into UIView. You can set them to be zero:

UILabel *label = [[UILabel alloc] initWithFrame:CGRectZero];
label.layoutMargins = UIEdgeInsetsMake(0, 0, 0,0);

But you'd have to do it manually for every view. You could automate this for your own subviews by setting them after init and then overriding the setter with a version that throws any values passed in away. However... In general, its best to go with the flow and not fight the frameworks so I'd really suggest not trying to switch them off or ignore them.

like image 71
Rog Avatar answered Sep 20 '22 02:09

Rog


Simply hold Option key (⌥) in the constraints pop-up to toggle between constraining to edge VS margin of views. Simple!

See full answer here: http://blog.manbolo.com/2014/10/09/xcode-6-auto-layout-margin-annoyances

like image 27
Marchy Avatar answered Sep 23 '22 02:09

Marchy