如何消除“Leading and Trailing constraints ...... there is already a center constraint”警告

How to eliminate “Leading and Trailing constraints … there is already a center constraint” warning

我正在尝试在 'or' UILabel 附近添加两条 1 像素线(由 UIViews 构成)。

除了我在 Interface Builder 中收到来自第一张图片的警告外,一切看起来都很好并且按预期工作:

Leading and Trailing constraints with relation "Equal To" can cause unhelpful limitations on the space the text can fill when there is already a center constraint.

我尝试将约束从 = 更改为 >= 或 <=,但没有成功。

知道如何摆脱这个警告吗? 谢谢!

Constraints of the first line

Constraints of the label

Constraints of the second line

如何代替标签,在具有标签宽度的行之间设置一个空的 UIView?然后将没有 left/right 约束的标签设置为以空视图为中心。这样空视图将适应标签而不限制它。

由于“或”标签上的“将中心 X 对齐到:安全区域”约束,因此存在警告。要消除警告:

  1. 从“or”标签中删除“Align Center X to: Safe Area”约束。
  2. 在左右两行之间添加“等宽”约束。

通过这两项更改,约束系统仍将强制使标签居中,但不会有导致警告的 center-x 约束。