I have several custom uibuttons on my view. I want to create a toggle button which when pressed, it will loop through all the UIButtons and enable a background image for them.
What I have 开发者_Python百科done is to use an image as a background, then created clickable parts of it using blank custom buttons. I want this toggle function to then show the buttons.
My plan is to create a subclassed UIButton for the "hidden" buttons. When the toggle button is pressed, the code should then set the background image for each of these buttons to a "reddot.png". That stays on the screen until the toggle button is pressed again - this then disables each sub classed uibuttons background image.
What's the best way to do this?
I would advise you to not subclass UIButton for two reasons. First, UIButton is actually a class-cluster, which makes subclassing rather difficult. Secondly, I don't think it is needed in your case.
Simply create all the buttons as custom buttons. You can customize their appearance using methods like [button setHidden:]
and [button setBackgroundImage:forState:]
. The toggle button could then simply by linked to an IBAction, which would apply the appropriate customizations to the other buttons.
精彩评论