Reputation: 117
I have this small problem that i cannot figure out. I have about 16 buttons and they are connected as an outlet collection to my controller.And also they have an action method which makes the buttons change their state from default to selected. Im trying to change all the buttons' images for only default state. So i run a loop through the array and set their image for the default state using setImage: forState: method. However the method changes the images for all states( Default and selected states ).
This is the setter method for my outlet collection
- (void) setCardsButton:(NSArray *)cardsButton
{
_cardsButton = cardsButton;
for (UIButton *button in cardsButton) {
[button setImage:[UIImage imageNamed:@"card.png"] forState:UIControlStateNormal];
}
[self updateView];
}
Upvotes: 9
Views: 4033
Reputation: 119031
If you don't specify an image for another state, the image for the 'normal' (UIControlStateNormal
) state will be used instead. So, explicitly set the image you want to be used for state UIControlStateSelected
.
If the 'normal' state isn't set then the system default is used.
Upvotes: 3
Reputation: 318854
Any properties you set for the "Normal" state are used for all other states not explicitly set otherwise. This is stated in the docs for UIButton setImage:forState:
. If you want a different image for other states, you need to call setImage:forState:
for the other states as well.
Upvotes: 15