NSTimer and using REAL time

Discussion in 'iOS Programming' started by jjardim, Jan 14, 2010.

  1. jjardim macrumors newbie

    Mar 19, 2008
    I'm trying to use a UISlider to act as a Time limit. Problem is that the values go to .99 before flipping to 1.

    My code so far is

    int _min = (int)mySlider.value;
    NSLog(@"Slider Int Minutes %i",_min);
    NSString *str = [NSString stringWithFormat:@"%.02f",mySlider.value];
    int stringLength = [str length];
    NSRange range = NSMakeRange(0, stringLength);
    NSString *newStr = [str stringByReplacingOccurrencesOfString:@"." withString:@":" options:NSCaseInsensitiveSearch range:range];
    NSLog(@"Old String: '%@' --> New String: '%@'", str, newStr);

    So the slider works, but I would like once the decimal place hits .60 it increases by 1 and resets the decimals to .00

    Screenshot Attached.

    Jason Jardim

    Attached Files:

  2. dejo Moderator


    Staff Member

    Sep 2, 2004
    The Centennial State
    I'm gonna suggest you just set the max value of your slider to the amount of time you want in seconds and then just convert the current slider value from the float into minutes & seconds.
  3. jjardim thread starter macrumors newbie

    Mar 19, 2008
    Found my solution

    Just wanted to contribute back - here is what I did

    int timerInt = (int)mySlider.value;
    lblSliderValue.text = [NSString stringWithFormat:@"%02d:%02d", timerInt / 60, timerInt % 60];
    I converted the UISlider properties to Seconds in IB

Share This Page