【问题标题】:How to resolve auto layout constraints for my view如何为我的视图解决自动布局约束
【发布时间】:2020-02-29 10:37:57
【问题描述】:

我需要你的帮助。 如何解决自动布局的警告。

以下是我的组件层次结构:

视图控制器
查看
- 查看
--表格视图
---表格单元格
1. 标题标签
2. 编辑按钮
3.删除按钮

我提供了如下约束:

标题标签:

Leading space to superview
trailing space to Edit button
bottom space to superview
top space to superview  

编辑按钮

trailing space to remove button
leading space to title label
bottom space to superview
top space to superview

删除按钮

Trailing space to superview
width = 40
leading space to edit button
align center Y
height = 40

我收到标题标签、编辑和删除按钮的警告“需要 X 和宽度”。

有什么帮助吗?

【问题讨论】:

  • 您确定该错误吗?我试图复制相同的内容并仅针对固定宽度约束收到警告。可以分享截图吗?

标签: ios objective-c ios-autolayout


【解决方案1】:

我建议您为情节提要组件使用自动布局固定按钮,我重新创建了您的视图,这就是我为组件所做的。

对于标题标签:

对于按钮:

对于移除按钮:

最后修复了标签的尾随空格问题。

【讨论】:

    【解决方案2】:

    Edit buttonWidth Constraint设置为40,与Remove button width 相同。

    编辑按钮

    trailing space to remove button
    leading space to title label
    width = 40  
    bottom space to superview
    top space to superview
    

    如果按钮宽度不固定,那么您需要更新 内容拥抱优先级 Horizontal 价值。

    选择“编辑”按钮并将 Content Hugging Priority Horizontal 值 250 更改为 251

    选择标题标签并将 Content Hugging Priority Horizontal 值 250 更改为 249

    希望这会有所帮助。

    【讨论】:

    • 我无法修复编辑按钮的宽度,因为它包含文本。删除按钮只有图像,所以我有固定的宽度。但即使在给出宽度 >= 105 之后,它仍然会给我警告,因为预期的宽度和高度与实际不同
    • 文字是固定的吗?如果固定,那么您可以设置宽度限制。
    • 文本是固定的,但本地化可以改变宽度。
    • @iAsh 你检查过这个吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-26
    • 2021-05-13
    相关资源
    最近更新 更多