我为按钮的状态 Normal、Highlighted 和 Selected 设置了图像,但是当按钮处于选定状态并按下/突出显示它时,我没有看到突出显示的图像,而只是看到灰色的图像.选择按钮时是否可以设置图像为高亮状态?
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:为选中状态设置图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!