简体   繁体   English

在UIStackView中为视图添加大小约束

[英]Adding Size Constraints for Views inside a UIStackView

I currently have a UIStackView that I add views to, it fits a maximum of 10 views along with a button. 我目前有一个UIStackView,可以向其中添加视图,它最多可以容纳10个视图以及一个按钮。 The issue however, is that although the views I add are equal size, the button is not. 但是,问题是,尽管我添加的视图大小相等,但按钮不是。

I have tried adding a constraint that determines sets the button's equal to 1/11th of the StackViewSize (so that all of the views can fit equally), but it just seems to break all the other constraints. 我尝试添加一个约束,该约束确定按钮的设置等于StackViewSize的1/11(这样所有视图都可以均等地容纳),但似乎只是打破了所有其他约束。

How can I give the button size without breaking a million constraints? 如何在不突破百万约束的情况下提供按钮尺寸?

Currently the height of the button is adjusted with each new view added, but that's just ugly. 当前,按钮的高度是在添加每个新视图时进行调整的,但这很丑陋。

First of all, set height and width to that button according to your requirement using AutoLayout. 首先,使用AutoLayout根据您的要求为该按钮设置高度和宽度。 Then select your stack view from the Document Outline(in your view controllers hierarchy) & then in Attribute Inspector set its Distribution to 'Fill Proportionally'. 然后从Document Outline(在视图控制器层次结构中)选择堆栈视图,然后在Attribute Inspector中将其Distribution设置为“按比例填充”。 Add some spacing if you want. 如果需要,请添加一些间距。

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

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