iOS 上带刻度线的水平滑块
我可以在iOS上实现带有刻度线的水平滑块吗?没有像 MacOS 那样的选项。
Can i realise a horizontal slider with tick marks on iOS? There is not such option like in MacOS.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
实际上,我在公司网站上写了一个关于如何执行此操作的教程:
http:// fragmentlabs.com/blog/making-talking2trees-part-3-77
这个问题的快速答案是我编写的自定义方法,上面的文章对此进行了解释:
您基本上会将此方法应用于视图那位于 UISlider 后面,它会以适当的间隔创建刻度线。您可以通过修改ticksDivider 变量来更改可见的刻度数。上面的示例为每个滑块创建一个值,除非滑块的 MaximumValue 属性大于 10(我的滑块的值为 5、40 和 120),在这种情况下,我将该值除以 10。
您必须使用 offsetOffset 值和
xPos += offset+...
之后的浮点值,以考虑拇指图像和滑块帽插图的宽度(因此拇指按钮似乎位于每个按钮的中心)。I actually wrote a tutorial on how to do this on my company's website:
http://fragmentlabs.com/blog/making-talking2trees-part-3-77
The quick answer for this is a custom method I wrote, and which is explained in the article above:
You'd basically apply this method to a view that sits behind your UISlider, and it creates the tick marks at the appropriate intervals. You can change how many ticks are visible by modifying the ticksDivider variable. The above example creates one per slider value unless the slider's maximumValue property is greater than 10 (my sliders had values of 5, 40 and 120), in which case I divided the value by 10.
You have to play with the offsetOffset value and the float value after
xPos += offset+...
to account for the width of your thumb image and slider cap insets (so the thumb button appears to be centered over each).来自@CarlGoldsmith - 你必须自己编程; iOS 上的 UISlider 没有该功能。
From @CarlGoldsmith - You'd have to program that yourself; UISliders on iOS don't have that functionality.
虽然 ctlockey 的解决方案确实有效,但我想要一些更简单的解决方案,但也允许拇指在用户释放它时捕捉到最接近的任何刻度线。
我的解决方案如下。它是 UISlider 的子类,仅重写两个方法。它是简单的框架,但将成为更复杂版本的基础。
While ctlockey's solution certainly works, I wanted something simpler but also that allowed the thumb to snap to whichever tick mark it is closest to when the user releases it.
My solution is below. It is a subclass of UISlider that only overrides two methods. It is bare bones but would be a foundation for a more complex version.