欢迎光临
我们一直在努力

日期选择器

建站超值云服务器,限时71元/月

日期选择器

项目介绍:

DatePicker

日期选择器,日期时间选择,时间选择器,年月日时分

github下载地址:https://github.com/Zws-China/DatePicker

如果觉得对你还有些用,顺手点一下star吧 (。♥‿♥。) 你的支持是我继续的动力。

可设置属性

宏定义
#define RGB(x,y,z) [UIColor colorWithRed:x/255.0 green:y/255.0 blue:z/255.0 alpha:1.0]


可设置的属性
//确定按钮颜色
@property (nonatomic,strong)UIColor *doneButtonColor;

//年-月-日-时-分 文字颜色(默认橙色)
@property (nonatomic,strong)UIColor *dateLabelColor;

//滚轮日期颜色(默认黑色)
@property (nonatomic,strong)UIColor *datePickerColor;

//限制最大时间(默认2099)datePicker大于最大日期则滚动回最大限制日期
@property (nonatomic, retain) NSDate *maxLimitDate;

//限制最小时间(默认0) datePicker小于最小日期则滚动回最小限制日期
@property (nonatomic, retain) NSDate *minLimitDate;

//大号年份字体颜色(默认灰色)想隐藏可以设置为clearColor
@property (nonatomic, retain) UIColor *yearLabelColor;

//隐藏背景年份文字
@property (nonatomic, assign) BOOL hideBackgroundYearLabel;

//默认滚动到当前时间
-(instancetype)initWithDateStyle:(WSDateStyle)datePickerStyle CompleteBlock:(void(^)(NSDate *))completeBlock;

//滚动到指定的的日期
-(instancetype)initWithDateStyle:(WSDateStyle)datePickerStyle scrollToDate:(NSDate *)scrollToDate CompleteBlock:(void(^)(NSDate *))completeBlock;

弹框的类型

typedef enum{
DateStyleShowYearMonthDayHourMinute  = 0,    //年-月-日-时-分
DateStyleShowMonthDayHourMinute,             //月-日-时-分
DateStyleShowYearMonthDay,                   //年-月-日
DateStyleShowMonthDay,                       //月-日
DateStyleShowHourMinute                      //时-分

}WSDateStyle;

1、年月日时分(DateStyleShowYearMonthDayHourMinute)

//_________________________年-月-日-时-分____________________________________________
//年-月-日-时-分
WSDatePickerView *datepicker = [[WSDatePickerView alloc] initWithDateStyle:DateStyleShowYearMonthDayHourMinute CompleteBlock:^(NSDate *selectDate) {

NSString *dateString = [selectDate stringWithFormat:@"yyyy-MM-dd HH:mm"];
NSLog(@"选择的日期:%@",dateString);
[btn setTitle:dateString forState:UIControlStateNormal];
}];
datepicker.dateLabelColor = [UIColor orangeColor];//年-月-日-时-分 颜色
datepicker.datePickerColor = [UIColor blackColor];//滚轮日期颜色
datepicker.doneButtonColor = [UIColor orangeColor];//确定按钮的颜色
[datepicker show];

这里写图片描述

2、月日时分(DateStyleShowMonthDayHourMinute)

WSDatePickerView *datepicker = [[WSDatePickerView alloc] initWithDateStyle:DateStyleShowMonthDayHourMinute CompleteBlock:^(NSDate *selectDate) {

NSString *date = [selectDate stringWithFormat:@"MM-dd HH:mm"];
NSLog(@"选择的月日时分:%@",date);
}];
[datepicker show];

这里写图片描述

3、年月日(DateStyleShowYearMonthDay)

WSDatePickerView *datepicker = [[WSDatePickerView alloc] initWithDateStyle:DateStyleShowYearMonthDay CompleteBlock:^(NSDate *selectDate) {

NSString *date = [selectDate stringWithFormat:@"yyyy-MM-dd"];
NSLog(@"选择的年月日:%@",date);

}];
[datepicker show];

这里写图片描述

4、年月(DateStyleShowYearMonth)

WSDatePickerView *datepicker = [[WSDatePickerView alloc] initWithDateStyle:DateStyleShowYearMonthDay CompleteBlock:^(NSDate *selectDate) {

NSString *date = [selectDate stringWithFormat:@"yyyy-MM-dd"];
NSLog(@"选择的年月日:%@",date);

}];
[datepicker show];

这里写图片描述

5、月日(DateStyleShowMonthDay)

WSDatePickerView *datepicker = [[WSDatePickerView alloc] initWithDateStyle:DateStyleShowMonthDay CompleteBlock:^(NSDate *selectDate) {

NSString *date = [selectDate stringWithFormat:@"MM-dd"];
NSLog(@"选择的月日:%@",date);

}];
[datepicker show];

这里写图片描述

6、时分(DateStyleShowHourMinute)

WSDatePickerView *datepicker = [[WSDatePickerView alloc] initWithDateStyle:DateStyleShowHourMinute CompleteBlock:^(NSDate *selectDate) {

NSString *date = [selectDate stringWithFormat:@"HH:mm"];
NSLog(@"选择的时分:%@",date);

}];
[datepicker show];

这里写图片描述

7、指定日期

//_____________________指定日期2011-11-11 11:11_______________________________
NSDateFormatter *minDateFormater = [[NSDateFormatter alloc] init];
[minDateFormater setDateFormat:@"yyyy-MM-dd HH:mm"];
NSDate *scrollToDate = [minDateFormater dateFromString:@"2011-11-11 11:11"];

WSDatePickerView *datepicker = [[WSDatePickerView alloc] initWithDateStyle:DateStyleShowYearMonthDayHourMinute scrollToDate:scrollToDate CompleteBlock:^(NSDate *selectDate) {

NSString *date = [selectDate stringWithFormat:@"yyyy-MM-dd HH:mm"];
NSLog(@"选择的日期:%@",date);
[btn setTitle:date forState:UIControlStateNormal];

}];
datepicker.dateLabelColor = RGB(65, 188, 241);//年-月-日-时-分 颜色
datepicker.datePickerColor = [UIColor blackColor];//滚轮日期颜色
datepicker.doneButtonColor = RGB(65, 188, 241);//确定按钮的颜色
datepicker.hideBackgroundYearLabel = YES;//隐藏背景年份文字
[datepicker show];

这里写图片描述

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 日期选择器
分享到: 更多 (0)