Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

EnigMoiD

macrumors member
Original poster
Aug 10, 2007
99
0
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?
 
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?
 
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?

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.
 
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?
 
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?

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.
 
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.

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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.