如何使用UIButton作为切换开关 [英] How to use a UIButton as a toggle switch
问题描述
我正在使用自定义类型的UIButton,我想要的是像切换开关一样使用它来改变图像。就像点击它之前一样,如果以前没有处于选定模式,它应该进入选定模式,否则反之亦然。它也将有一个不同的图像,当它被选中时,它将有不同的图像。
I am using a UIButton of custom type and what I want is use it like a toggle switch with the change of image. Like when it is clicked if previously it was not in selected mode it should go in selected mode or otherwise vice-a-versa. Also it will have a different image and when it is selected it will have a different image when it is not.
我无法以编程方式进行,有没有很容易做到这一点。
I am not able to do it programatically, is there any good easy way to do this.
推荐答案
我相信这篇文章有一个更好的解决方案:具有UISwitch功能的iPhone UIButton
I believe this post has a better solution : iPhone UIButton with UISwitch functionality
UIButton已内置切换功能。是一个选定的属性,您可以根据状态设置和更改外观。
UIButton has toggling built in. There is a selected property that you can set and change the skins based on the state.
这篇关于如何使用UIButton作为切换开关的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!