设置UISlider的刻度 [英] Setting tick marks for UISlider
问题描述
是否有任何方法可以为UISlider设置刻度线.NSSlider有一个叫做-(void)setNumberOfTickMarks:(NSInteger)numberOfTickMarks
.但是,UISlider似乎没有一个.
Is there any method for setting tick marks for UISlider. NSSlider has something called
- (void)setNumberOfTickMarks:(NSInteger)numberOfTickMarks
. But UISlider does not appear to have one.
我想做的就是将滑块值设置为0、1、2、3、4等,如果说我将最小值设置为0,最大值设置为5.现在,这样的UISLider返回的值是0.0、0.1、0.2,0.3 4.8,4.9,5.0基于我在上面给出的示例.
What i want to do is get the slider values as 0,1,2,3,4 etc if say i set the min as 0 and max as 5. Now as such UISLider returns something like 0.0,0.1,0.2,0.3 etc 4.8,4.9,5.0 based on the example i gave above.
有帮助吗?
推荐答案
UISlider
没有任何刻度.
要获得您指定的行为,您必须将滑块返回的数字四舍五入到最接近的整数.
To get the behaviour you specify you'll have to round the number returned by the slider to the nearest integer.
因此,当您开始滑动时,滑块报告的值为0.1或0.2时,请将其四舍五入.直到达到0.5时,再向上舍入为1.
So when you start sliding, and the slider reports a value of 0.1 or 0.2, round that to 0. Until it hits 0.5, when you round up to 1.
然后,当滑块停止滑动时,可以将其值设置为四舍五入的数字,这将使滑块对齐"到该位置,就像捕捉到刻度线一样.
Then when the slider stops sliding, you can set it's value to the number you rounded to, which will make the slider "snap" to that position, kind like snapping to a tick mark.
如果要使用视觉标记,则必须自己实现.
If you want visual tickmarks, you'll have to implement that yourself.
这篇关于设置UISlider的刻度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!