I need a slider for displaying real time in slider-label from 12-00 AM to 11-45 PM with step size 15 minutes. But I just have no idea how to do it. Сan anybody give some suggest
If you just need a time chooser with slider, use the following code in the sliderChanged: handler:
- (IBAction)onSliderChange:(id)sender {
UISlider *slider = (UISlider *)sender;
NSUInteger numberOfSlots = 24*4 - 1; //total number of 15mins slots
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"h-mm a"];
NSDate *zeroDate = [dateFormatter dateFromString:@"12-00 AM"];
NSUInteger actualSlot = roundf(numberOfSlots*slider.value);
NSTimeInterval slotInterval = actualSlot * 15 * 60;
NSDate *slotDate = [NSDate dateWithTimeInterval:slotInterval sinceDate:zeroDate];
[dateFormatter setDateFormat:@"h-mm a"];
self.timeLabel.text = [dateFormatter stringFromDate:slotDate];
}