自定义UISwitch与图像 [英] Custom UISwitch with image

查看:131
本文介绍了自定义UISwitch与图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在项目中实现自定义开关。目前我发现我们无法改变UISwitch的实现方式,如下图所示。我已经关注帖子并通过stackoverflow和其他博客搜索,但没有找到所需的解决方案。一种方法是使用UISegmented控件,如帖子,但这也无法解决我的问题。

I need to implement a custom switch in a project. Currently what I have found is that we cannot alter with UISwitch in way to implement as shown in below image. I've followed posts and googled through stackoverflow and other blogs but didn't found a solution as desired. One way is to go with UISegmented control as in this post, but that too doesn't solves my problem.

提前感谢您的任何帮助

推荐答案

创建自己的交换机有什么困难? UISwitch是一个控件,基本上只是一个发送消息的视图 - 具有两个状态。您可以这样设置:

What's so hard about creating your own switch? A UISwitch is a control, essentially just a view that sends a message -- with two states. You could set it up like this:


  • 容器视图:带圆角的简单视图(设置视图图层的cornerRadius 和背景颜色

左图:显示您要显示的图像的图像视图在左侧,即示例的复选标记

left image: an image view that displays the image you want to show on the left side, i.e. the check mark for your example

右图:显示您要在右侧显示的图像的图像视图,即示例的X标记

right image: an image view that displays the image you want to show on the right side, i.e. the X mark for your example

滑块:显示开关滑块部分的图像视图,设置在其他两个图像视图上方

slider: an image view showing the slider portion of the switch, set above the other two image views

当用户点击或滑动控件时,使用Core Animation将滑块移动到交换机的另一侧并更新状态控制并快速淡入新状态的背景颜色。将控件的操作发送到目标。

When the user taps or swipes the control, use Core Animation to move the slider to the other side of the switch and update the state of the control and do a quick fade to the background color for the new state. Send the control's action to the target.

这篇关于自定义UISwitch与图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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