+ (NSArray*) getSliderNumbers { NSArray *sliderNumbers = [NSArray arrayWithObjects:@"10", @"20", @"30", @"40", @"50", @"60", @"70", @"80", @"90", @"100", @"150", @"200", @"250", @"300", @"350", @"400", @"450", @"500", @"600", @"700", @"800", @"900", @"1", @"1.5", @"2.0", @"2.5", @"3.0", @"3.5", @"4", @"4.5", @"5", @"5.5", @"6", @"6.5", @"7", @"7.5", @"8", @"8.5", @"9", @"9.5", @"10", @"15", @"20", @"25", @"30", @"35", @"40", @"45", @"50", @"55", @"60", @"65", @"70", @"75", @"80", @"85", @"90", @"95", @"100", @"200", @"300", @"400", @"500", @"600", @"700", @"800", @"900", nil]; return sliderNumbers; }
above is loaded into the array after creating the instance:
Set up the slider:
customSlider.minimumValue = 0.0f; customSlider.maximumValue = (CGFloat)[sliderNumbers count] - 1; customSlider.continuous = YES; customSlider.value = customSlider.maximumValue;
Method called by UIControlEventValueChanged
- (void) sliderMove:(UISlider*) theSlider { NSInteger numberLookup = lroundf([theSlider value]); NSString *distanceString = [sliderNumbers objectAtIndex:numberLookup]; CGFloat distanceInMeters; if (numberLookup > 21) { [self.indicator.indicatorLabel setText:[NSString stringWithFormat:@"%@ km", distanceString]]; distanceInMeters = [distanceString floatValue] * 1000; } else { [self.indicator.indicatorLabel setText:[NSString stringWithFormat:@"%@ m", distanceString]]; distanceInMeters = [distanceString floatValue]; } if (oldDistanceInMeters != distanceInMeters) { [self.delegate distanceSliderChanged:distanceInMeters]; oldDistanceInMeters = distanceInMeters; } }
It even requires string formatting for the user interface, for example. “200 m” or “1.5 km” and updates the delegate with the distance number in meters to use when sorting my results with a predicate.