Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent a UILabel from blocking a touch to a parent UIButton in Swift?

I have a UIButton that has four child UILabels that contain information about the button's functionality. When I click the center of the button the action does not fire because it is being blocked by the UILabels but when I click the outside of the button the action does fire. Is there a way to prevent the UILabels from blocking the action firing?

like image 503
KevinZ Avatar asked Dec 03 '22 22:12

KevinZ


1 Answers

You'll need to set isUserInteractionEnabled = false on any view that is above the button, or a subview of it.

By default UILabel have it set to false, but as you mentioned in the comments, UIStackView does not. So calling isUserInteractionEnabled = false on it will do the trick ┌( ಠ‿ಠ)┘

like image 102
tomahh Avatar answered Mar 18 '23 17:03

tomahh