xcode 如何像这个InterfaceBuilder设置一样自动调整标签?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10497834/
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
How to autosize label like this InterfaceBuilder Settings?
提问by brush51
i want to set the autosize settings for an uilabel programmatically.
i want exactly the same settings like in the interface builder settings i set, see here:
我想以编程方式为 uilabel 设置自动大小设置。
我想要与我设置的界面构建器设置完全相同的设置,请参见此处:
http://imageshack.us/photo/my-images/545/bildschirmfoto20120508u.png/
http://imageshack.us/photo/my-images/545/bildschirmfoto20120508u.png/
so how can i set it programmatically? i want full width.
那么我如何以编程方式设置它?我想要全宽。
i have tried it with:
我已经尝试过:
titleLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
But when i use this, my label is very strange (in portraitmode is the width 0 and in landscape approx 100).
但是当我使用它时,我的标签很奇怪(纵向模式下宽度为 0,横向模式下约为 100)。
so how to do?
那怎么办?
回答by Lefteris
From what I see you want full width, but flexible bottom, so you should use this autoresizing mask value:
从我看到的你想要全宽但灵活的底部,所以你应该使用这个自动调整掩码值:
titleLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleTopMargin;