【发布时间】:2015-02-08 14:28:45
【问题描述】:
我有一个带有 typeSystem 的按钮,该按钮在正常状态下具有特定图像,而在选定状态下具有不同图像。问题是,当我将按钮设置为选中状态时,图像不会显示,并且按钮的背景会以淡色着色。 有没有办法阻止它发生并显示我为选定状态设置的图像?
【问题讨论】:
标签: ios iphone uibutton tintcolor
我有一个带有 typeSystem 的按钮,该按钮在正常状态下具有特定图像,而在选定状态下具有不同图像。问题是,当我将按钮设置为选中状态时,图像不会显示,并且按钮的背景会以淡色着色。 有没有办法阻止它发生并显示我为选定状态设置的图像?
【问题讨论】:
标签: ios iphone uibutton tintcolor
您应该用self.yourButton = [UIButton buttonWithType:UIButtonTypeCustom]; 替换它,而不是使用buttonWithType:UIButtonTypeSystem,这将放弃您获得的有色选择选项。然后你可以改变它的状态图像如下:
[self.yourButton setBackgroundImage:[UIImage imageNamed:@"unselectedImage.png"] forState:UIControlStateNormal];
[self.yourButton setBackgroundImage:[UIImage imageNamed:@"selectedImage.png"] forState:UIControlStateSelected];
现在色调不会显示,您选择/未选择的图像将保留该图像,直到您再次更改状态
【讨论】: