Xcode 6 为布局边距设置默认值或禁用它们
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25915487/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Xcode 6 set default values for layout margins or disable them
提问by Spail
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)?
Xcode 6 的这个新特性有点烦人。大多数时候我不需要设置相对于边距的偏移量,如果我这样做了,我可能想使用默认值 16 以外的值。有没有办法更改默认值或完全禁用我的项目(或所有项目)的边距我的 Xcode 中的项目)?
采纳答案by Rog
You cannot "turn them off" because they're built into UIView. You can set them to be zero:
您不能“关闭它们”,因为它们内置于 UIView 中。您可以将它们设置为零:
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.
但是您必须为每个视图手动执行此操作。您可以通过在 init 之后设置它们,然后使用抛出任何传入值的版本覆盖 setter 来为您自己的子视图自动执行此操作。但是...总的来说,最好顺其自然,不要与框架作斗争,所以我真的建议不要尝试关闭它们或忽略它们。
回答by Marchy
Simply hold Option key (?) in the constraints pop-up to toggle between constraining to edge VS margin of views. Simple!
只需在约束弹出窗口中按住 Option 键 (?) 即可在约束到边缘 VS 视图边距之间切换。简单的!
See full answer here: http://blog.manbolo.com/2014/10/09/xcode-6-auto-layout-margin-annoyances
在此处查看完整答案:http: //blog.manbolo.com/2014/10/09/xcode-6-auto-layout-margin-annoyances