具有 UISwitch 功能的 iPhone UIButton
有没有办法用开关状态的自定义图形来实现 UISwitch? 或者作为另一种选择,具有 UISwitch 功能的 UIButton?
Is there either a way to implement UISwitch with custom graphics for the switch-states?
Or as an alternative the other way round, an UIButton with UISwitch functionality?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
UIButton
已经支持“切换”功能。只需在 Interface Builder 中为“选定状态配置”设置不同的图像,并使用
UIButton
的selected
属性来切换其状态。UIButton
already supports a "switch" functionality.Just set a different image in Interface Builder for the "Selected State Configuration", and use the
selected
property ofUIButton
to toggle its state.将图像设置为在选定状态下显示:
然后在选择器内部进行触摸时,设置:
如果您希望取消另一个按钮的选择,请设置:
set the image to show on selected state:
and then on touch up inside selector, set:
if you want this to cancel another button's selection, set:
为了构建上面 PGB 和 nurne 所说的内容,在设置状态并附加选择器(事件方法)后,您需要将此代码放入该选择器中。
To build on what PGB and nurne said above, after you set your states and attach a selector (event method) you would want to put this code in that selector.
对于有编程倾向的:
For programmatically inclined: