[英]How do I use constraints / auto layout in Xcode's Interface Builder to properly scale images and fonts?
I'm trying to make a user interface in Xcode's Interface Builder such that: 我正在尝试在Xcode的Interface Builder中创建用户界面,例如:
Simple goals, I think… I have accomplished all of this programmatically using custom code previously, but I'd rather do it the "right way" and design this properly in Interface Builder and let it handle all of the layout for me. 我认为简单的目标……我以前已经使用自定义代码以编程方式完成了所有这些工作,但是我宁愿以“正确的方式”做到这一点,并在Interface Builder中正确设计它,并让它为我处理所有布局。
Let's say I have designed in Interface Builder a screen for a small form-factor iPhone like this: 假设我在Interface Builder中为这样的小型iPhone设计了一个屏幕:
Now say this look and feel I'm happy with for iPhone 4s devices and would just like to scale everything up proportionally to the width for newer, larger iPhone form factors. 现在说一下这种外观,我对iPhone 4s设备感到满意,并且只想按比例将所有内容按比例放大,以适应更新,更大的iPhone尺寸。
If I were to use the older "springs and struts" method, this almost gives me what I want on a larger form factor... except that everything stretches height-wise (not simply based on aspect ratio of original design's width to height.) You can notice particularly the "logo image" is stretched too tall. 如果我要使用较旧的“弹簧和支柱”方法,那么这几乎可以在更大的外形尺寸下满足我的要求……除了所有内容都沿高度方向拉伸(不只是基于原始设计的宽高比)。 )您会特别注意到“徽标图像”拉伸得太高。 And the fonts aren't being scaled up on labels or buttons either. 而且字体也不会在标签或按钮上按比例放大。
I've also tried using "constraints", particularly just tackling the issue of image scaling proportionally, basing it on the aspect ratio of the container, and am not having any luck whatsoever. 我还尝试过使用“约束”,特别是仅按比例处理图像缩放问题,并基于容器的纵横比进行处理,而没有任何运气。
Here I reset the springs and struts to their defaults, and add constraint to the original design's logo image: 在这里,我将弹簧和支柱重置为其默认值,并为原始设计的徽标图像添加了约束:
Looking at the larger form factor, nothing has in fact changed: 从更大的尺寸来看,实际上没有任何变化:
(And yes, despite the fact there's layout errors reported, "fixing" them in any way has no net effect on the scaling / lack of scaling in the image.) (是的,尽管报告了布局错误,但是以任何方式“修复”它们都不会对图像的缩放/缺乏缩放产生实际影响。)
So just to restate-- how do I do the following with Xcode / Interface Builder constraints? 因此,只需重申一下-如何使用Xcode / Interface Builder约束执行以下操作?
Thanks in advance. 提前致谢。
What you can do is to make width and height using aspect ratio. 您可以使用宽高比设置宽度和高度。
I have added a multiplier respect to superview 我为Superview添加了一个乘数方面
I have set a label like this. 我已经设置了这样的标签。
And From attribute inspector i set like this: 从属性检查器,我这样设置:
All views are center aligned. 所有视图均居中对齐。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.