内容拥抱不起作用

时间:2015-12-24 21:09:09

标签: ios ios-autolayout

我有一个有子视图的UIView 我希望黄色视图只在标签的长度上增长 不幸的是它增长到屏幕的最大宽度减去我在白色视图和黄色视图左右边距之间给出的强制边距

我已在白色和黄色视图中将内容拥抱优先级设置为502,501

我如何使这项工作?

enter image description here

1 个答案:

答案 0 :(得分:1)

我从你的问题中了解到你希望你的黄色视图具有内在的内容大小,即它的大小应该取决于标签的大小。为此请遵循以下步骤 -

1.将以下约束添加到黄色视图

           a.Center horizontally in container.

           b.Center vertically in container.
  1. 现在到图像视图添加以下约束

           a. Leading and Trailing space with respect to yellow view.
    
           b. Top space with respect to yellow view and Bottom space with respect to label.
    
  2. 现在向标签添加以下约束

          a. Leading and trailing space with respect to yellow view.
          b. Bottom space with respect to yellow view.
    
  3. 这将为您提供所需的结果。现在标签的前导和尾随空间固定为黄色视图,因此标签将增长,黄色视图将自动增长。

    You can see the required constraints added in the screenshot.

相关问题