adit adit - 2 months ago 10
iOS Question

adding a UILabel as subview of UIButton doesn't trigger button action

I have a

UIButton
and I am adding a subview to the
UIButton
which is a
UILabel
. When I tap on the
UILabel
the action of the button doesn't get triggered. Is there an easy fix so that the touch event gets passed to the
UIButton
when the
UILabel
is tapped?

I am thinking of adding a gesture recognizer to the
UILabel
which then triggers the action of the
UIButton
, not sure if there's a much more simpler way.

Answer

You can probably just disable user interaction to your label.

_yourLabel.userInteractionEnabled = NO;
Comments