简体   繁体   English

iOS:如何正确获取水平堆叠视图内按钮的约束?

[英]iOS: How to get the constraints for button inside horizontal stack-view right?

I am new to iOS development and am following the udacity course for iOS development. 我是iOS开发的新手,并且正在学习iOS开发的udacity课程。 I am stuck at the lesson whose link I have given below. 我被困在下面的课程中。

https://classroom.udacity.com/courses/ud585/lessons/6991272849/concepts/72642287220923# https://classroom.udacity.com/courses/ud585/lessons/6991272849/concepts/72642287220923#

I am unable to reduce the size of stop button in the last stack view. 我无法减小最后一个堆栈视图中“停止”按钮的大小。 I tried reducing the size of the button by setting the width constraint of the button to 64 and height of stack-view containing that button to 64. But XCode gives error of conflicting constraints. 我尝试通过将按钮的宽度约束设置为64并将包含该按钮的堆栈视图的高度设置为64来减小按钮的大小。但是XCode给出了约束冲突的错误。

I am attaching screenshots below for reference. 我附上以下屏幕截图,以供参考。

我得到的错误的图像

我设定的约束的扩展视图

What I actually want is: 我真正想要的是:

https://d17h27t6h515a5.cloudfront.net/topher/2016/November/582a8006_interface/interface.png https://d17h27t6h515a5.cloudfront.net/topher/2016/November/582a8006_interface/interface.png

You can take a uiview inside your last stack and then You can take your stop button. 您可以在最后一个堆栈中使用uiview,然后可以使用停止按钮。 Then you can change properties of your "stop" UIbutton. 然后,您可以更改“停止” UIbutton的属性。

Another option if you want to keep the existing constraints you have in the screenshot from the course is to change the properties of the stack in Interface builder. 如果要保留课程屏幕快照中的现有约束,另一种选择是在“界面”构建器中更改堆栈的属性。

For topmost stack 对于最高堆栈

set alignment to fill, and distribution to fill proportionally. 设置对齐方式以填充,并设置分布以按比例填充。

For your stack at bottom with button in it - 对于底部有按钮的堆栈 -

set alignment to centre and distribution equal centering. 将对齐方式设置为中心,分布等于中心。

You may be getting the conflicting constraints because when you tried to "change" the height and width you actually added additional height and width constraints. 您可能会遇到冲突的约束,因为当您尝试“更改”高度和宽度时,实际上添加了其他的高度和宽度约束。 Check them in the measurements editor and if your see constraints with the >= symbol, you should delete those. 在度量编辑器中检查它们,如果看到带有> =符号的约束,则应删除它们。 Click edit on the height and width remaining to make the changes. 单击剩余高度和宽度上的编辑以进行更改。 This should fix the problem. 这应该可以解决问题。 You may need to clean and build as well. 您可能还需要清洁和建造。

Hope that helps! 希望有帮助!

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

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