Multiple Similar Image Buttons

Discussion in 'iOS Programming' started by EnigMoiD, Mar 27, 2010.

  1. EnigMoiD macrumors member

    Joined:
    Aug 10, 2007
    #1
    I'm making an app that has a bunch of buttons which all use the same stretchable images for their pressed and normal states. I've been using separate outlets for each button, but it seems like there should be a better way. I tried subclassing UIButton, but apparently you can't do that. Is there a simpler way to do what I'm trying to do that requires less work?
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    Do you show all the buttons at once? If not just create one and add/remove it from the views.

    Also why can't you subclass UIButton?
     
  3. EnigMoiD thread starter macrumors member

    Joined:
    Aug 10, 2007
    #3
    I am showing all the buttons at once. And after trying to subclass UIButton and having it not work, I did some reading and found that people more commonly subclass UIControl or UIView because UIButton is complex to subclass.

    Maybe my problem was doing everything in UIButton's init method...

    EDIT: Never mind, I had been doing the code in the drawRect method, which was fine, I guess I just gave up, because I fixed it and it works now!! Thanks for the help.
     
  4. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #4
    OK, so why not create 1 button in IB with an outlet pointing to it then copy it however many times you want in code adding each copy to the view?
     
  5. EnigMoiD thread starter macrumors member

    Joined:
    Aug 10, 2007
    #5
    Tried that too, then found out that outlets can only apply to one button at a time... well I found a solution anyway...edited my above post.
     
  6. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #6
    Glad you have a solution but I wasn't actually suggesting you re-set the outlet. I'd have just stored the new references in a NSMutableArray. Maybe I'm in the minority but I create the entire interface of my apps in code without using Interface Builder at all.
     

Share This Page