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]);
足够简单。这就是我所看到的:
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>
因此看起来所有按钮状态都指向同一图像,即图像0xd6b5a80
然而,当用户点击按钮后,在按下按钮之后但在抬起脏手指之前,按钮看起来不同。
基本上当我按下按钮时,按钮的底角不再是圆形。
发生了什么事?
答案 0 :(得分:7)
即使您尚未设置特定的高亮显示图像,按钮也会在进入高亮显示状态时调整图像。为防止这种情况,请使用:
imgBtnReloadAllButton.adjustsImageWhenHighlighted = NO;
答案 1 :(得分:0)
这是因为当您按下按钮时,iOS会将您用作(背景)图像的图像渲染。您可以通过将图像设置为图像而不是背景图像来防止这种情况。