简体   繁体   English

如何设置视图的最大高度限制?

[英]How to set max height constraint for a view?

I have a view and I want it's height to be equal to %20 of its parent. 我有一个视图,我希望它的高度等于其父级的%20。 However, its height should be less than 64px. 但是,其高度应小于64px。 How to set this up in storyboard? 如何在情节提要中进行设置?

Like this (the two views are called Superview and Subview; ignore everything but the first and last constraints in the screenshot): 这样(两个视图分别称为“ Superview”和“ Subview”;忽略屏幕截图中的第一个和最后一个约束除外):

在此处输入图片说明

The subview has an internal height constraint that's a less-than-or-equal-to-64 constraint. 子视图具有内部高度约束,该约束小于或等于64约束。 The height equality constraint between the superview and subview has a multiplier of 0.2 (that's your 20%) but a priority of 999. 超级视图和子视图之间的高度相等约束的乘数为0.2 (即您的20%),但优先级为999。

Result (superview is black, subview is white, subview is at top of superview): when the superview is short, subview is 20% of its height: 结果(超级视图为黑色,子视图为白色,子视图位于超级视图的顶部):当超级视图较短时,子视图为其高度的20%:

在此处输入图片说明

... but when superview is tall, subview cannot grow beyond 64 points in height. ...但是当超级视图很高时,子视图的高度不能超过64点。 (Points, not px. Points are not pixels. Be careful.) (点不是px。点不是像素。请注意。)

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM