本文介绍了在UIStackView中增加UIButton的面积的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在UIStackView中嵌入了几个UIButton.我了解UIStackView在布局时仅采用UIButton的固有大小.但是我想在UIStackView中增加UIButton的高度/宽度.没有UIStackView,我可以轻松地增加或减小UIButtons的框架大小. UIStackView有什么用?

I have couple of UIButtons embedded in UIStackView. I understand UIStackView takes only the intrinsic size of UIButton when laying it out. But I want to increase height/width of UIButton when inside UIStackView. Without UIStackView, I can easily increase or decrease UIButtons frame size. What is the deal with UIStackView?

详细信息:假设我给了3个仅包含UIImages而没有文本的UIButton.按钮1是80x80,按钮2的图像是30x30,按钮3的图像是30x30.我希望按钮2和3的触摸面积至少为45x45,而不会拉伸图像.当不在UIStackView中时,我可以像这样简单地调整UIButton的大小.但是使用UIStackView时,所有按钮的大小都是图像的大小(本征大小),我不知道如何解决.

Detail: Let's say I gave 3 UIButtons with only UIImages and no text. Button 1 is 80x80, button 2 image is 30x30, button 3 image is 30x30. I would like touch area of button 2 and 3 to be atleast 45x45 without stretching the image. I can simply resize UIButton like this when it's not in UIStackView. But with UIStackView, all button sizes are the size of images (intrinsic size) which i don't know how to fix.

推荐答案

如果将宽度/高度约束添加到按钮堆栈视图,则会根据约束而不是按钮的固有大小来为其子视图设置大小.

If you add the width/height constraints to the buttons stack view will size it subviews based on the constraints and not the intrinsic size of buttons.

这篇关于在UIStackView中增加UIButton的面积的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-19 02:19