当我当时触摸按钮时,我想更改图像 &当我松开触摸按钮时,图像原样.
我想应用下面的代码,但这不是我的期望.
请给我任何建议.....
-(IBAction)actionEnter:(id)sender{if ([sender isSelected]) {[发件人 setImage:[UIImage imageNamed:@"enter-hover.png"]forState:UIControlStateNormal];[发件人设置选择:否];} 别的 {[发件人 setImage:[UIImage imageNamed:@"enter.png"]forState:UIControlStateSelected];[发件人 setSelected:YES];}
您可以为此使用 UIControlStateHighlighted.
<上一页>[myButton setImage:[UIImage imageNamed:@"enter-hover.png"]forState:UIControlStateHighlighted];您也可以从界面生成器中通过将图像设置为突出显示状态来进行设置.
When I touch the button at that time I want to change image & when i release the touch button image is as it is.
I want to apply below code but it's not with my expectation.
please give me any suggestion.....
-(IBAction)actionEnter:(id)sender{
if ([sender isSelected]) {
[sender setImage:[UIImage imageNamed:@"enter-hover.png"]
forState:UIControlStateNormal];
[sender setSelected:NO];
} else {
[sender setImage:[UIImage imageNamed:@"enter.png"]
forState:UIControlStateSelected];
[sender setSelected:YES];
}
You can use UIControlStateHighlighted for this.
[myButton setImage:[UIImage imageNamed:@"enter-hover.png"] forState:UIControlStateHighlighted];
You can also set this from interface builder by setting the image for highlighted state.
这篇关于UIButton - 触摸更改图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!