iOS UIButton behind UIImageVIew

nashyo

macrumors 6502
Original poster
Oct 1, 2010
299
0
Bristol
I have a label positioned in my view that has a custom UIButton behind it. I have selected 'hidden' so that the button doesn't appear to the user. When the label is touched, the button activates a segue to the next view controller. This works fine.

Trying the same technique with UIImageView is not proving so fruitful.

I have even tried laying a round rect button that isn't hidden on top of the image (partially covering the image), which segues successfully. But as soon as I choose 'hidden', the button is not touchable.

Why does this work for labels but not for UIImageView?

Thanks
 

nashyo

macrumors 6502
Original poster
Oct 1, 2010
299
0
Bristol
UIButton?

First, why are you using multiple controls when the standard UIButton can show text and/or images?
I've found that the text on a button doesn't position itself very well. Especially when the text is dynamic and of an unpredictable length. To be honest, I haven't tried putting an image onto a button yet, but surely a UIImageView object would be more suitable for that?
 

dantastic

macrumors 6502a
Jan 21, 2011
570
676
No.
You can still change font, size positioning of text in a button. A button is very much capable of having an image. You probably want to be using a button here...

In either case having a "hidden" button behind the view isn't a solution.

You want to attach a UIGestureRegognizer to the view you want tappable. Then you can make your label or image view behave like a button rather than having a button behind.
 

dejo

Moderator
Staff member
Sep 2, 2004
15,981
450
The Centennial State
I've found that the text on a button doesn't position itself very well. Especially when the text is dynamic and of an unpredictable length.
UIButton's titleLabel property is a UILabel. You can do all the positioning, etc. you want with it.

To be honest, I haven't tried putting an image onto a button yet, but surely a UIImageView object would be more suitable for that?
A UIButton with an image can highlight when touched and can easily be setup with an action message. To me, it's much more suitable.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.