如何使按钮保持按下状态? [英] How do I make a button stay pressed?

查看:113
本文介绍了如何使按钮保持按下状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,所以我正在构建一个几乎完整的应用程序.我只是有一个问题,当我按我的按钮时,它发出声音,并且按钮的图像改变了.但是,图像仅在被触摸或突出显示"时才会更改,我希望按钮图像在声音效果的持续时间内保持不变,然后在声音效果之后,我希望它恢复为原始图像.无论如何,我是否可以设置UIButton的设置时间"或突出显示"选项的内容?

Okay so I have an app I'm building that is almost complete. I'm just having one problem, when I press my button it makes a sound and the button's image changes. However the image only changes when it is being touched or "highlighted" and I would like the buttons image to remain changed through the duration of the sound effect then after the sound effect I would like it to revert back to the original image. Is there anyway I can set up a UIButton "set time" or something for the "highlighted" option?

有时候我会感到很尴尬,因为当我非常出色地处理核心编码并在几天之内接近完成一个完整的应用程序时,我似乎被这些最琐碎的事情所绊倒,但这是我的第一个应用程序,我我还是XCode的新手.我真的很感谢这个社区的帮助,总是能使我前进的任何答案!

I feel so embarrassed sometimes, because I seem to get tripped up by these most trivial things, when I handle the core coding exceptionally well and near finish a full app in a days time, but this is my first app and I'm still a newbie to XCode. I really appreciate this community's help any answer that pushes me forward is always appreciated!

对于在iPhone上键入的问题格式,我进一步表示歉意,希望它不要太笨拙或缺乏细节.如果有人需要更多详细信息,请询问!

I further apologize for my questions formatting I typed this on my iPhone I hope it's not too awkward or lacking in detail. If anyone needs more detail just ask!

推荐答案

1.您不希望在突出显示和选定状态下对图像进行任何反射.因此,您只需为所有状态都放置相同的图片,例如

1.You dont want any reflection of image at highlighted and selected state. so you just put same image for all state like

[btnClear setBackgroundImage:[UIImage imageNamed:@"blue_button.png"]
                            forState:UIControlStateNormal];
[btnClear setBackgroundImage:[UIImage imageNamed:@"blue_button.png"]
                            forState:UIControlStateHighlighted];
[btnClear setBackgroundImage:[UIImage imageNamed:@"blue_button.png"]
                            forState:UIControlStateSelected];

2.现在,如果您想在声音停止时更改图像而不是进行更改

2.Now if you want image change at sound stop time than make

[btnClear setBackgroundImage:[UIImage imageNamed:@"red_button.png"]
                            forState:UIControlStateNormal];
[btnClear setBackgroundImage:[UIImage imageNamed:@"red_button.png"]
                            forState:UIControlStateHighlighted];
[btnClear setBackgroundImage:[UIImage imageNamed:@"red_button.png"]
                            forState:UIControlStateSelected];

然后再次单击按钮,只需切换第一个图像即可.

And again on button click you just toggle image with first one.

这篇关于如何使按钮保持按下状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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