UIButton behind UIImageVIew

Discussion in 'iOS Programming' started by nashyo, Jan 17, 2012.

  1. nashyo macrumors 6502

    nashyo

    Joined:
    Oct 1, 2010
    Location:
    Bristol
    #1
    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
     
  2. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    First, why are you using multiple controls when the standard UIButton can show text and/or images?
     
  3. nashyo thread starter macrumors 6502

    nashyo

    Joined:
    Oct 1, 2010
    Location:
    Bristol
    #3
    UIButton?

    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?
     
  4. dantastic macrumors 6502

    dantastic

    Joined:
    Jan 21, 2011
    #4
    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.
     
  5. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #5
    UIButton's titleLabel property is a UILabel. You can do all the positioning, etc. you want with it.

    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.
     

Share This Page