如何将“最大约束"设置为屏幕高度的20%? [英] How can I set the top Constraint to be 20 percent of the screen height?

查看:117
本文介绍了如何将“最大约束"设置为屏幕高度的20%?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在控制器的视图中有一个UIImageView,距离视图顶部的屏幕高度为20%.即我想将屏幕高度的20%设置为UIImageViewtop Constraint.

I have an UIImageView in the in the controller's view with a distance of 20% of the screen height from the top of the view. ie I want to set the 20 % of the screen height as the top Constraint of the UIImageView.

是否可以在不向容器视图中添加透明视图的情况下实现此操作,这就是我现在要做的(通过将其高度设置为屏幕高度的20%)?

Can I implement this without adding a transparent view, which is how I do it now (by setting its height to be 20% of the screen Height), to the container view ?

推荐答案

您可以在IB/StoryBoard本身中进行操作.由于您希望图像视图和其超级视图之间的顶部垂直空间始终为超级视图高度的20%,因此与将图像视图的高度设置为其超级视图高度的80%并固定图像视图的底部相同最重要的是因此,您可以消除该透明视图的添加.

You can do it in the IB/StoryBoard itself. Since you want the top vertical space between the image view and it's superview to be always 20% of the height of the superview, it is same as setting the image view's height to be 80% of it's superview's height and pinning the bottom of image view to the bottom of it's superview. Hence, you can eliminate that transparent view from being added.

步骤(这里我仅考虑垂直约束)
1.将约束从图像视图的底部拖动到其超级视图的底部.
2.将等高约束从图像视图拖到其超级视图.在 Size Inspector 中将此约束的乘数值更改为8:10(下面的屏幕快照).

Steps (I'm only considering vertical constraints here):
1. Drag a constraint from the bottom of the image view to the bottom of it's superview.
2. Drag an equal heights constraint from the image view to it's superview. Change the multiplier value of this constraint to 8:10 in the Size Inspector (Screenshot's attached below).

这篇关于如何将“最大约束"设置为屏幕高度的20%?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆