简体   繁体   中英

Increase area of UIButton in 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?

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.

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

For this purpose I usually use the contentEdgeInsets property. If it is not sufficient, you would need to add some autolayout constraints.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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