Increase area of UIButton in UIStackView

时光毁灭记忆、已成空白 提交于 2020-01-24 22:30:08

问题


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.


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/53416177/increase-area-of-uibutton-in-uistackview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!