- (void)updateFollowButton {
if (!followButton.selected) {
[followButton setImage: [UIImage imageNamed:kFollowButtonImage] forState:UIControlStateNormal];
[followButton setImage:[UIImage imageNamed:kButtonFollowHighlighted] forState:UIControlStateHighlighted];
[followButton setBackgroundImage:[UIImage imageNamed:kFollowButtonImage] forState:UIControlStateDisabled];
} else {
[followButton setImage:[UIImage imageNamed:kUnfollowButtonImage] forState:UIControlStateNormal];
[followButton setImage:[UIImage imageNamed:kButtonfUnfollowHighlighted] forState:UIControlStateHighlighted];
[followButton setImage:[UIImage imageNamed:kUnfollowButtonImage] forState:UIControlStateDisabled];
}
}
When I set selection state then I call an updateFollowButton to refresh button normal image and highlight image. Why this simple code not work?
Thanks for the answers.
You should use the selected state. bitwise-or your states with
UIControlStateSelectedto set the values for the 3 different states you have but whenselected==YES:Then, the state is handled automatically (meaning once you have configured all the states, you don’t have to call your method again to change the images anymore, like you do with your
updateFollowButton):