UIButton:为选中的突出显示状态设置图像 [英] UIButton: set image for selected-highlighted state

查看:23
本文介绍了UIButton:为选中的突出显示状态设置图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为按钮的状态设置了图像正常、突出显示和选定,但是当按钮处于选定状态并按下/突出显示它时,我没有看到突出显示的图像,而只是看到变灰的图片.当按钮被选中时,是否可以将图像设置为突出显示状态?

I set an images for button's states Normal,Highlighted and Selected, but when the button in selected state and I press/highlight it I didn't see my highlighted image but just grayed picture. Is it possible to set an image for highlighted state when the button selected?

我的代码:

[button setImage:[UIImage imageNamed:@"normal.png"] forState:UIControlStateNormal];
[button setImage:[UIImage imageNamed:@"pressed.png"] forState:UIControlStateHighlighted];
[button setImage:[UIImage imageNamed:@"checked.png"] forState:UIControlStateSelected];

当我这样做时:

[button setSelected:YES];

然后按下按钮,pressed.png"图像没有被选中.

and press the button, the "pressed.png" image doesn't select.

推荐答案

我找到了解决方案:需要添加附加行

I found the solution: need to add addition line

[button setImage:[UIImage imageNamed:@"pressed.png"] forState:UIControlStateSelected | UIControlStateHighlighted];

这篇关于UIButton:为选中的突出显示状态设置图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆