Typ*_*nda 11 objective-c uibutton ios
我知道我的情况可能很少见,但在这种情况下如何禁用UIButton色调?
我有一个定制的UIButton,它已归属于标题,以帮助显示不同颜色和alpha的按钮模式.

在我的自定义按钮.m文件中,我设置了这样的东西
[self setBackgroundImage:[self imageWithColor:[UIColor grayColor]] forState:UIControlStateSelected];
Run Code Online (Sandbox Code Playgroud)
当选择按钮时,将使背景颜色变为灰色
但实际结果如下:

我认为文本颜色如何变成白色是因为UIButtons的色调效果.
我可以将背景设置为灰色,而文本仍然保持按钮选定状态下属性标题中设置的颜色吗?
谢谢
mad*_*dhu 34
yourbutton = [UIButton buttonWithType:UIButtonTypeCustom];
(or)
Run Code Online (Sandbox Code Playgroud)
如果你在故事板中放置了按钮....选择按钮类型作为自定义而不是系统.
您可以setImage:forState:在UIButton子类中重写,然后将呈现方式更改为.alwaysOriginal。
override func setImage(_ image: UIImage?, for state: UIControlState) {
let newImage = image?.withRenderingMode(.alwaysOriginal)
super.setImage(newImage, for: state)
}
Run Code Online (Sandbox Code Playgroud)