iOS时间选择器timepicker

jopen 9年前

时间选择器

` 支持多种格式 YearMonthDayHourMinute,YearMonthDay,MonthDayHourMinute,HourMinute,DayHourMinute,DayHourMinuteHourMinute 这里只展示一种格式,超出范围的颜色也同样支持添加,可以设置需要显示的时间间隔

//效果图  iOS时间选择器timepicker

使用方法: WMCustomDatePicker *picker = [[WMCustomDatePicker alloc]initWithframe:CGRectMake(0, 40, [UIScreen mainScreen].bounds.size.width, 214) Delegate:self PickerStyle:WMDateStyle_DayHourMinute]; picker.minLimitDate = [NSDate date];

  • (void)finishDidSelectDatePicker:(WMCustomDatePicker *)datePicker date:(NSDate *)date { if ([date compare:[NSDate date]] == NSOrderedDescending) { self.timeStr = [self dateFromString:date withFormat:@"yyyy-MM-dd HH:mm"]; }

}

//根据date返回string

  • (NSString *)dateFromString:(NSDate *)date withFormat:(NSString *)format { NSDateFormatter *inputFormatter = [[NSDateFormatter alloc] init]; [inputFormatter setDateFormat:format]; NSString *dateStr = [inputFormatter stringFromDate:date]; return dateStr; }

项目主页:http://www.open-open.com/lib/view/home/1449196292983