问题
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