views:

809

answers:

2

now it show as float how to show it as integer

sliderCtl = [[UISlider alloc] initWithFrame:frame];
    sliderCtl.minimumValue = 1;
    sliderCtl.maximumValue = 15;
    sliderCtl.continuous = NO;
    sliderCtl.value = 1;
    [sliderCtl setShowValue:YES];
A: 

You could truncate or round the value from the slider and then update it to give the user feedback about the change (it would appear to snap to the integer value when the user releases).

gerry3
the solusion is i must update it by my self right?
RAGOpoR
That should work.
gerry3
+1  A: 

if you want your slider to snap to different integer values, you could use something like this in your valueChanged-function:

-(IBAction)valueChanged:(UISlider*)sender {
    int discreteValue = roundtol([sender value]); // Rounds float to an integer
    [sender setValue:(float)discreteValue]; // Sets your slider to this value
}

This will snap the slider after releasing your finger to values like 1,2,...,15 based on the distance between two numbers. If for instance you released the slider at 2.4, it'll snap back to 2, whereas at 2.6 it would snap to 3.

thgc