简体   繁体   English

Xcode约束无法按预期工作

[英]Xcode constraints not working as expected

在此处输入图片说明

As you can see in the image above, the label on the far right is being placed off-screen. 如上图所示,最右边的标签不在屏幕上。 This label should show '14:23'. 此标签应显示“ 14:23”。

Here's a screenshot of the constraints on the central label: 这是中心标签上的约束的屏幕截图:

在此处输入图片说明

The 'Time' label has a constraint attaching it to the right side. “时间”标签具有将其附加到右侧的约束。

I need this layout to be compatible with both iPad and iPhone. 我需要这种布局才能与iPad和iPhone兼容。 How can I stop the Time label being pushed off the screen? 如何停止将时间标签推离屏幕?

This probably has nothing to do with the constraint you marked, but instead is an issue of the content compression resistance priorities of the three labels. 这可能与您标记的约束无关,而是三个标签的内容压缩抗性优先级的问题。 You need to specify them in an order that fits your need. 您需要按照适合您的顺序指定它们。 Eg if you absolutely want to make sure that the 'B123' and the '14:23' label can be fully read, specify a content compression resistance of 1000 (required) for those two labels and a lower priority for the middle label. 例如,如果您绝对要确保可以完全读取“ B123”和“ 14:23”标签,请为这两个标签指定一个内容抗压强度为1000(必需),并为中间标签指定一个较低的优先级。

The compression resistance describes, how important it is for the label not to be smaller as its required space. 抗压强度描述了标签不小于其所需空间的重要性。

The opposite of this is the content hugging priority. 相反的是内容优先。 This priority describes how important it is for the label not to be larger than the content requires it. 此优先级描述了标签不超过内容要求的重要性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM