I am guessing your problem is this (from the Apple Documentation for setImage:forState:
):
In general, if a property is not specified for a state, the default is to use the
UIControlStateNormal
value. If theUIControlStateNormal
value is not set, then the property defaults to a system value. Therefore, at a minimum, you should set the value for the normal state.
So, you cannot simply unset images for some states because the default image will get used.
I see a couple of solutions to this problem:
- Use a transparent image for the states you want to show through rather than
nil
- Give your cards a
UIImageView
subview that you set to the card back image. If the card is face down, usesetHidden:
to show the subview. If the card is face up, usesetHidden:
to hide the subview. I would probably use the– addTarget:action:forControlEvents:
method within your custom button class to register a custom method that shows or hides the card back subview.
Note that you could easily take option 2 a step further by displaying the front of the card in a subview as well and then you can easily animate a flip transition between those two subviews so that the card "flips" over when pressed.