“固定的前导和尾随约束可能导致削波”。错误? [英] "Fixed leading and trailing constraints may cause clipping" bug?

查看:569
本文介绍了“固定的前导和尾随约束可能导致削波”。错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里有



我希望标签居中,我希望文本距离边距至少20像素,因此我为前导和尾随设置了固定约束。 Xcode希望我将其中一个更改为大于或等于约束,但在这种情况下,文本将不会完全居中(我尝试过)。



我想要的只是中心文本,它不会太靠近边距,但现在我无法在不触发警告的情况下实现这一点。



关于如何获取的任何想法解决这个问题?它真的是一个错误,还是我做错了什么?






编辑:这是一个截图显示错误。约束不是直接在视图控制器中,而是在我用作表视图的背景的子视图中。如果我删除这些限制,警告就会消失;如果我把它们添加回去,它会再次出现。我在一个新项目中尝试了这个并且无法重现它,我不知道它为什么会在这里发生。





修改:



这是另一个例子。当右边约束设置为大于或等于时,所有的好:





一旦我将其设置为相等,热潮:



解决方案

如果您仍在寻找答案,请在特定情况下尝试在标签上设置比例宽度,并在视图控制器的视图中水平居中。



清除标签上的所有约束,右键单击从标签拖动到背景视图并选择等宽在容器中水平居中在容器中垂直居中从弹出菜单中。



既然你说你想要在标签的左右两边都有20px的保证金,那就编辑乘数等宽约束并将其设置为 widthOfBackgroundView - 40)/ widthOfBackgroundView



所以假设你的背景视图的宽度是 414 ,乘数应该是414分之374



宽度减去40 乘数的原因是它在标签的两边都覆盖了20px。这应该会让你的警告消失,并按照你期望的方式布置标签。



我有同样的问题,并且能够以这种方式修复警告。希望这有帮助!


There's this other question here that addresses a similar issue, but in that case Xcode's behavior is correct, just annoying.

In my case, however, I think it's actually a bug:

That label can have an unlimited number of lines, so it'll never be clipped, the text will just break.

It works fine with every localization:

I want the label to be centered and I want the text to be at least 20 pixels away from the margins, so I set fixed constraints for the leading and trailing. Xcode wants me to change one of them to a "greater than or equal" constraint, but in that case the text won't be perfectly centered (I tried).

All I want is centered text that won't be too close to the margins, but now I can't accomplish that without triggering that warning.

Any ideas on how to fix this? Is it really a bug, or am I doing something wrong?


Edit: Here's a screenshot showing the error. The constraints aren't directly in a view controller, but in a subview that I use as the backgroun for a table view. If I remove those constraints the warning goes away; if I add them back it shows up again. I tried this in a new project and couldn't reproduce it, I have no idea why it's happening here.

Edit:

Here's another example. When the right constraint is set to "greater than or equal" all's well:

As soon as I set it to "equal", boom:

解决方案

If you're still looking for an answer, in your particular case, try setting a proportional width on your label and center horizontally in the view controller's view.

Clear all your constraints on the label, right-click drag from the label to the Background View and select Equal Widths, Center Horizontally in Container, and Center Vertically in Container from the popup menu.

Now since you said you wanted 20px margin both to the left and right of your label, edit the Multiplier on the equal width constraint and set it to widthOfBackgroundView - 40)/widthOfBackgroundView.

So let's say the width of your background view is 414, the multiplier is supposed to be 374/414.

The reason for the width minus 40 multiplier is it covers 20px on either sides of the label. This should make your warning go away and layout the label the way you're expecting it to be.

I had the same issue and was able to fix the warnings this way. Hope this helps!

这篇关于“固定的前导和尾随约束可能导致削波”。错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆