iPhone垂直拨动开关 [英] iPhone vertical toggle switch

查看:140
本文介绍了iPhone垂直拨动开关的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为iPhone创建一个垂直切换开关控件(沿着UISwitch但是垂直滑动)。

I'm trying to create a vertical toggle switch control for the iPhone (along the lines of UISwitch but vertical sliding).

我想知道现有控件是否存在已经存在或者是否有任何好的教程解释了为iPhone创建自定义控件的基础知识。

I was wondering whether an existing control already existed or if there are any good tutorials that explain the basics of creating custom controls for the iPhone.

目前我已尝试使用仿射变换来创建垂直切换一个基本的UIswitch,它的工作原理除了滑块与滑块轨道相比太小,因此我正在寻找有关编写自定义控件的信息。

Currently I've tried using affine transforms to create the vertical switch from a basic UIswitch, and it works except that the slider is too small compared to the slider track, thus I'm looking for information on writing custom controls.

任何方向都是非常感谢。

Any direction is much appreciated.

推荐答案

您可以使用UIButton和两个图像使其看起来像垂直切换开关和交换图像,具体取决于切换状态。

You could use a UIButton and two images to make it appear like a vertical toggle switch and swap images depending on switch state.

子类UIButton,添加开关状态,图像交换等,根据需要使用。

Subclass UIButton, add the switch state, image swapping, etc, use as needed.

编辑 - 另一种方法是完全自定义控件。你继承了 UIControl 并添加类似 UISwitch 的功能(即:initWithFrame,on,setOn:animated :)。

EDIT -- The other way to go is a completely custom control. You subclass UIControl and add functions similar to UISwitch's function (ie: initWithFrame, on, setOn:animated:).

您还需要发送状态更改的事件,类似于UISwitch所做的事情:

You also need to send an event with the state changes, similar to what UISwitch does with:

[self sendActionsForControlEvents: UIControlEventValueChanged];

当触摸在交换机上移动时,您可以实现beginTrackingWithTouch,continueTrackingWithTouch和endTrackingWithTouch来滑动切换图像。我这样做是为了创建一个2D滑块。 UISwitch也有自己的本地化,例如ON / OFF变为0/1。

You implement beginTrackingWithTouch, continueTrackingWithTouch and endTrackingWithTouch to slide the switch images as the touch moves across the switch. I did this to create a 2D slider. UISwitch also does its own localization, the ON/OFF changes to 0/1 for example.

这篇关于iPhone垂直拨动开关的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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