UISlider具有某些可能的值 [英] UISlider with certain possible values

查看:168
本文介绍了UISlider具有某些可能的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我愿意做这个小工具:

可以选择ABC。

如果有人已经做过类似的事情,不知道吗?如果没有,你会怎么做?

Any idea if someone already did something similar? If not, how would you do it?

推荐答案

我个人使用标准的UISlider并向valueChanged处理程序添加逻辑,这样,一旦用户将滑块拖动到刻度上的任意点,代码就会确定哪个是最接近的有效值,并将手动将值设置为有效数字。

Personally I'd use a standard UISlider and add logic to the valueChanged handler, so that once the user has dragged the slider to an arbitrary point on the scale, the code determines which is the nearest 'valid' value, and would manually set the value to a valid number.

例如如果用户将滑块拖动到0.9,则到有效点的距离为0.9(到A),0.4(到B)和0.1(到C)。因此代码将选择C,并将slider.value设置为1.0。如果您可以为该属性设置动画,则无法记住副手,但您可能可以。这对用户来说看起来更好。

E.g. if the user drags the slider to 0.9, the distances to valid points are 0.9 (to A), 0.4 (to B) and 0.1 (to C). So the code would pick C, and set slider.value to 1.0. Can't remember off-hand if you could animate that property, but you probably can. That would look much nicer to the user.

对于视觉效果,我将创建一个容器类,其中包含一个UISlider,并为每个有效值创建一个UILabel。沿着滑块下方的刻度根据它们的位置排列这些标签并不太难。通过适当的自动调整大小,无论您如何更改容器视图的形状,控件仍应看起来正确。

For visuals, I'd create a container class that holds a UISlider, and a UILabel for each valid value. Arranging those labels along the scale underneath the slider according to their positions isn't too hard. With suitable auto-resizing, the control should still look correct no matter how you change the shape of the container view.

对于抛光,我可能还会调整字体对于选定标签,要加粗它或其他东西,以使该项目被选中显而易见。

For polish, I'd probably also tweak the font for the 'selected' label to bold it or something else to make it doubly obvious that the item has been selected.

这篇关于UISlider具有某些可能的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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