views:

618

answers:

2

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.

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.

Any help??

A: 

I just cast [slider value] to int to achieve this.

gammelgul
Casting to an int will perform truncation on the value, and so a value like 0.99 will become 0. Rounded it to the nearest integer will be a better option.
Jasarien
Thanks for your answers and time...Actually what i am doing is customizing my slider and putting a strip of image as the track image on slider. So when my slider slides, a different image gets selected. so at 0, one image, 1 another image, 2 another image...like that...But now since, the slider travels from 0.1->0.2 etc...Nothing happens at that time. Actually i dont want that. NSSLider does that exactly the way i want. Any workaround for that.
+1  A: 

UISlider doesn't have any tickmarks.

To get the behaviour you specify you'll have to round the number returned by the slider to the nearest integer.

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.

Jasarien
Thanks for your answers and time...Actually what i am doing is customizing my slider and putting a strip of image as the track image on slider. So when my slider slides, a different image gets selected. so at 0, one image, 1 another image, 2 another image...like that...But now since, the slider travels from 0.1->0.2 etc...Nothing happens at that time. Actually i dont want that. NSSLider does that exactly the way i want. Any workaround for that.
`UISlider` isn't a direct port of `NSSlider`, so it sounds like you'll have to subclass `UISlider` and implement the behaviour yourself.
Jasarien