Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIButton as a subview in UILabel

I am trying to dynamically add a UIbutton as a subview to UIlable. But I am not able to click the button. It seems that the label doesn't allow the buttonTapped event to occur.
Can somebody explain what exactly is happening here? and can anybody give me an alternative for this? thanks!

like image 626
Jayshree Avatar asked Jan 23 '26 03:01

Jayshree


2 Answers

funny, I got answer on my own after 5 mins of posting this question. It seems that I had to enable my userInteraction on the labels.

i.e. -

lbl.userInteractionEnabled=YES;
like image 178
Jayshree Avatar answered Jan 25 '26 19:01

Jayshree


Your question (and subsequent answer) don't speak to the wisdom (or lack thereof) of doing what you're attempting. UILabel objects aren't generally meant to be interactive, and placing a UIButton as a subview to the label, just because you can do it, doesn't sound at all like it's following the Apple HIG for iPhone.

like image 26
WineSoaked Avatar answered Jan 25 '26 17:01

WineSoaked



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!