Reputation: 1
[myButton setImage:[UIImage imageNamed:@"btn_normal"] forState:UIControlStateNormal];
[myButton setImage:[UIImage imageNamed:@"btn_highlighted"] forState:UIControlStateHighlighted];
[myButton setImage:[UIImage imageNamed:@"btn_highlighted"] forState:UIControlStateSelected];
myButton.showsTouchWhenHighlighted = YES;
I have tried this code and it is not working.
Upvotes: 0
Views: 111
Reputation: 135
Implement onTouchDown
action of that button and set button background image in that function by [btn setBackgroundImage: forState:]
Upvotes: 0
Reputation: 6673
You should use the setBackgroundImage:forState
. The setImage:forState
changes the image which is on the same depth level as the button title. Additionally the backgroundImage
is automatically fit to the button's view bounds. The image
is not.
Upvotes: 2