如果未显示图像,如何在顶部显示的标签上设置自动布局?

How to set autolayout on label which shows at the top if Image is not displayed?

我有一个视图,如果 post 有 "Image",我在视图顶部放置了图像视图,它显示图像,但是如果 post 没有图像,那么它不能。

现在我想设置如果没有图像,则位于图像视图底部的标签位于视图顶部。所以,它看起来很完美。

场景如下,请查看

> Image View | Label | Label | Label | Label | and so on...

现在,如果没有图像,那么我的视图是

>            | Label | Label | Label | Label | and so on...

但是,我想使用自动布局删除这个额外的 space,所以我的视图将如下所示

> | Label | Label | Label | Label | and so on...

如何使用 Autolayout 进行设置。

请帮帮我。

我想如果有任何图像你想显示 imageView 否则你必须显示 UiLabel.You 可以通过检查是否有图像使 UIImageview 隐藏为 false 和 UIlabel 来做到这一点在 else condition.hope 中隐藏到 true.And 反向 condition.hope 这项工作 you.If 你没有得到这个,请告诉我我会帮助 you.Thanks

试试这个:

请按照下面的截图进行操作希望对您有所帮助

试试这个:

对你的 class 中的第一个标签 a 属性 进行约束。然后在您的代码中,您可以相应地更新约束的 属性 称为 "constant"。就像 if (imageIsPresent) then myConstraint.constant=0 else my constraint.constant=someValue

不确定,但应该可以。