[英]IOS Label and View constraints height
I am really confused about constraints is iOS, i've read a lot of articles, but get stuck, when tried to set Height constraints of UIView according to UILabel content height. 我对约束确实感到困惑,因为iOS,我读过很多文章,但是在尝试根据UILabel内容高度设置UIView的 Height约束时陷入困境。 I know that is the common question, but i really don't understand the solutions.
我知道这是常见的问题,但是我真的不明白解决方案。 I thought that the main thing in this question is the constraint priority , but i can't set them properly.
我以为这个问题的主要内容是约束优先级 ,但是我无法正确设置它们。 In one case, the height of UIView wont change to 0, and in other UILabel height does not make any sense.
在一种情况下, UIView的高度不会更改为0,而在其他情况下, UILabel的高度没有任何意义。
So. 所以。 I've got:
我有:
And i want: 而且我要:
UIImageView - is just the icon. UIImageView-只是图标。 If there is no text, must be shrink to 0, if there is some text, must have height 32, top constraint 10, bottom constraint more or equals to 10.
如果没有文本,则必须缩小为0,如果有文本,则必须具有高度32,顶部约束10,底部约束大于或等于10。
Fix the problem, by adding height constraint programmatically. 通过以编程方式添加高度约束来解决此问题。 (don't like this)
(不喜欢这样)
You can make the constraints take full control of the label,image and view heights, if you set the priorities correctelly. 如果正确设置优先级,则可以使约束完全控制标签,图像和视图的高度。
Like this 像这样
The View is this 视图是这个
and this 和这个
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.