UIButton 色调颜色影响处于选中状态的按钮的背景颜色

UIButton tint color affected the background color of the button in selected state

我有一个 typeSystem 按钮,它在正常状态下有一个特定的图像,在选定状态下有一个不同的图像。问题是,当我将我的按钮设置为选中状态时,图像不会显示,并且按钮的背景颜色为淡色。 有什么办法可以阻止它发生并显示我为选定状态设置的图像吗?

而不是使用 buttonWithType:UIButtonTypeSystem,您应该将其替换为 self.yourButton = [UIButton buttonWithType:UIButtonTypeCustom];,这将放弃您获得的有色选择选项。然后你可以改变它的状态图像如下:

[self.yourButton setBackgroundImage:[UIImage imageNamed:@"unselectedImage.png"] forState:UIControlStateNormal];
[self.yourButton setBackgroundImage:[UIImage imageNamed:@"selectedImage.png"] forState:UIControlStateSelected];

现在不会显示色调,并且您的 selected/unselected 图像将保留该图像,直到您再次更改状态