user4951
user4951

Reputation: 33120

Why buttons look different when user is pressing it?

UIImage * imgBtnReloadAllButton = [UIImage resizeableImageWithCapInsets2:UIEdgeInsetsMake(5, 5, 5, 5) withName:@"search_in_this_area"];
[self.btnReloadAllButton setBackgroundImage:imgBtnReloadAllButton forState:UIControlStateNormal];


PO([self.btnReloadAllButton backgroundImageForState:UIControlStateHighlighted]);
PO([self.btnReloadAllButton backgroundImageForState:UIControlStateNormal]);
PO([self.btnReloadAllButton backgroundImageForState:UIControlStateSelected]);
PO([self.btnReloadAllButton backgroundImageForState:UIControlStateReserved]);
PO([self.btnReloadAllButton backgroundImageForState:UIControlStateApplication]);
PO([self.btnReloadAllButton backgroundImageForState:UIControlStateDisabled]);

Simple enough. This is what I see:

2013-03-19 15:22:22.349 BadgerNew[1724:c07] [self.btnReloadAllButton backgroundImageForState:UIControlStateHighlighted]: <_UIResizableImage: 0xd6b5a80>
2013-03-19 15:22:22.350 BadgerNew[1724:c07] [self.btnReloadAllButton backgroundImageForState:UIControlStateNormal]: <_UIResizableImage: 0xd6b5a80>
2013-03-19 15:22:22.350 BadgerNew[1724:c07] [self.btnReloadAllButton backgroundImageForState:UIControlStateSelected]: <_UIResizableImage: 0xd6b5a80>
2013-03-19 15:22:22.350 BadgerNew[1724:c07] [self.btnReloadAllButton backgroundImageForState:UIControlStateReserved]: <_UIResizableImage: 0xd6b5a80>
2013-03-19 15:22:22.382 BadgerNew[1724:c07] [self.btnReloadAllButton backgroundImageForState:UIControlStateApplication]: <_UIResizableImage: 0xd6b5a80>
2013-03-19 15:22:22.383 BadgerNew[1724:c07] [self.btnReloadAllButton backgroundImageForState:UIControlStateDisabled]: <_UIResizableImage: 0xd6b5a80>
(lldb) po imgBtnReloadAllButton
$0 = 0x0d6b5a80 <_UIResizableImage: 0xd6b5a80>

So it looks like all button states points to the same image, namely image 0xd6b5a80

Yet when user click the button, after pressing the button but before lifting their dirty finger, the button looks different.

Basically when I press the button the bottom corners of the buttons are no longer round.

What happened?

Upvotes: 2

Views: 139

Answers (2)

jrturton
jrturton

Reputation: 119272

Buttons adjust their image when entering the highlighted state, even if you haven't set a specific highlighted image. To prevent this, use:

imgBtnReloadAllButton.adjustsImageWhenHighlighted = NO;

Upvotes: 7

Leon
Leon

Reputation: 410

This is because iOS renders the image you use as (background) image when you press on the button. You could prevent this by setting the image as image and not as background image.

Upvotes: 0

Related Questions