【问题标题】:UIButton tint color affected the background color of the button in selected stateUIButton tint color 影响选中状态下按钮的背景颜色
【发布时间】:2015-02-08 14:28:45
【问题描述】:

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

【问题讨论】:

    标签: ios iphone uibutton tintcolor


    【解决方案1】:

    您应该用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];
    

    现在色调不会显示,您选择/未选择的图像将保留该图像,直到您再次更改状态

    【讨论】:

    • 谢谢 :) 我以前用过这个,我只是想知道是否可以将按钮作为类型系统,并具有相同的效果?我更喜欢 typeSystem 而不是 custom 的原因是因为我可以给按钮一个 tint 颜色,而在 typeCustom 中它不受它的影响。
    • @rcat24 您现在拥有的图像应该仍在显示。你在其他地方有问题。我只是在你最后一句话中回答这个问题,因为这似乎是你想要的结果。但是,您始终可以通过对所选图像进行 Photoshop 处理以包含您所追求的任何背景来模拟色调。
    猜你喜欢
    • 2022-07-07
    • 1970-01-01
    • 2018-10-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多