简体   繁体   English

如何解决Interface Builder Xcode中的stackview错误问题?

[英]How to solve the issue of a stackview bug inside Interface Builder Xcode?

I have a really strange bug found in Xcode's Interface Builder, and I hope someone else can tell me how to fix it, or at least tell me I'm not the only one. 我在Xcode的Interface Builder中发现了一个非常奇怪的错误,我希望其他人可以告诉我如何修复它,或者至少告诉我我不是唯一的错误。

When I try to add an UILabel and UITextview inside a stackView using the Interface Builder, the stack view will be stretch with a width of infinite. 当我尝试使用Interface Builder在stackView添加UILabelUITextview ,堆栈视图将以无限宽度拉伸。 For my UITextView I disabled the scroll and edit functions. 对于我的UITextView我禁用了滚动和编辑功能。

Before: 之前: 在此输入图像描述

This is after I combine both elements inside a StackView : 这是在我将两个元素组合在StackView

在此输入图像描述

When I use two UILabels and add those inside a StackView it's working correctly. 当我使用两个UILabel并在StackView添加它们时,它正常工作。

将堆栈视图本身的尾随和前导约束添加到超级视图或关闭具有明确定义的约束的项目应解决该问题

You need to add minimum 3 (most of the cases 4) constraints to your views in order to use autolayout. 您需要在视图中添加最少3个(大多数情况4)约束才能使用autolayout。

example code: 示例代码:

    [label.topAnchor constraintEqualToAnchor: self.topAnchor].active = YES;
    [label.bottomAnchor constraintEqualToAnchor: self.bottomAnchor].active = YES;
    [label.leadingAnchor constraintEqualToAnchor: self.leadingAnchor].active = YES;
    [label.trailingAnchor constraintEqualToAnchor: self.trailingAnchor].active = YES;

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

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