UISwitch 定制?
是否可以将图像添加到 UISwitch 背景,例如当状态为 ON 时(作为一个背景)和当状态为 OFF 时(另一背景图像)?
Is possible to add images to an UISwitch background,like when the state is ON (be one background) and when the state is OFF (another background image)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
要更改背景颜色(不是图像),您只需执行以下操作即可。这会更改领域中所有 UISwitch 控件的关闭颜色。
如果您想使用图像,请使用以下使用分段控件的酷技巧。
https://stackoverflow.com/a/5088099/1705353
如果你想写很多代码,你可以写你自己的控制。 Valeriy Van 指出: https://github.com/homick/iPhone-Snippets /tree/master/General
另外一个资源是:http://www.raywenderlich.com/23424/photoshop-for-developers-creating-a-custom-uiswitch 代码位于:http://cdn2.raywenderlich.com/wp-content/uploads/2012/10/CustomSwitchResources.zip
To change the background color (not image) all you have to do is below. This changes the off color for all UISwitch controls in realm.
If you want to use image, use the following cool hack of using the segmented control.
https://stackoverflow.com/a/5088099/1705353
If you want to write a lot of code, you can write your own control. Valeriy Van pointed to: https://github.com/homick/iPhone-Snippets/tree/master/General
Also another resource is: http://www.raywenderlich.com/23424/photoshop-for-developers-creating-a-custom-uiswitch with code at: http://cdn2.raywenderlich.com/wp-content/uploads/2012/10/CustomSwitchResources.zip
我想建议您遵循 自定义 UISwitch 和App Store批准有更好的想法,建议您创建一个自定义开关控件。
I would like to suggest you to follow Custom UISwitch & App Store approval to have a better idea, which is suggesting you to create a custom switch control.
您可以通过子类化
UIControl
来重新创建自定义UISwitch
。通过这样做,您可以完全控制开关的外观。你可以看看SevenSwitch
。我创建的自定义UISwitch
替代品。开/关颜色可以根据您的喜好定制。https://github.com/bvogelzang/SevenSwitch
You can recreate a custom
UISwitch
by subclassingUIControl
. By doing this you can have full control over what the switch looks like. You can look take a look atSevenSwitch
. A customUISwitch
replacement I've created. The on/off colors can be customized to your liking.https://github.com/bvogelzang/SevenSwitch