登录 立即注册
金钱:

Code4App-iOS开发-iOS 开源代码库-iOS代码实例搜索-iOS特效示例-iOS代码例子下载-Code4App.com

日期选择器

[复制链接]
来自: Zws丶 分类: iOS精品源码 上传时间: 2018-9-14 16:29:43
Tag:

项目介绍:

DatePicker

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

GitHub: https://github.com/Zws-China/DatePicker

PhotoShoot

这里写图片描述

可设置属性

宏定义
#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;

//默认滚动到当前时间
-(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,//年月日
DateStyleShowYearMonth,//年月
DateStyleShowMonthDay,//月日
DateStyleShowHourMinute,//时分
DateStyleShowYear,//年
DateStyleShowMonth,//月
DateStyleShowDayHourMinute,//日时分
}WSDateStyle;



类型1(DateStyleShowYearMonthDayHourMinute)

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

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



//_________________________年-月-日-时-分(滚动到指定的日期)_________________________
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);
}];
datepicker.dateLabelColor = RGB(65, 188, 241);//年-月-日-时-分 颜色
datepicker.datePickerColor = [UIColor blackColor];//滚轮日期颜色
datepicker.doneButtonColor = RGB(65, 188, 241);//确定按钮的颜色
datepicker.yearLabelColor = [UIColor clearColor];//大号年份字体颜色
[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(DateStyleShowMonthDay)

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

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

}];
[datepicker show];

这里写图片描述

类型5(DateStyleShowHourMinute)

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

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

}];
[datepicker show];

这里写图片描述

类型6(DateStyleShowYear)

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

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

}];
[datepicker show];

image

类型7(DateStyleShowMonth)

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

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

}];
[datepicker show];

image

类型8(DateStyleShowDayHourMinute)

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

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

}];
[datepicker show];

image

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

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

相关源码推荐:

我来说两句
*滑动验证:
所有评论(5)
一人无 2018-9-14 16:29:44
感谢分享,楼主V5~
回复
pp美景 2018-9-14 16:30:33
学习...学习...
回复
这是个逗比 2018-9-14 16:30:44
感谢大神~
回复
Yf8546 2018-9-14 16:30:47
写的真的很不错
回复
无限释囚 2018-9-14 16:30:54
感谢大神~
回复
t8569 2018-9-14 16:31:00
code4app好的代码demo真的很多,谢谢啦~
回复
407 1 0
联系我们
首页/微信公众账号投稿

帖子代码编辑/版权问题

QQ:435399051,742864542

如何获得代码达人称号?

代码贡献英雄榜
用户名 下载数
通过邮件订阅最新 Code4App 信息
上一条 /4 下一条
联系我们
关闭
合作电话:
13802416937
Email:
435399051@qq.com
商务市场合作/投稿
问题反馈及帮助
联系我们

广告投放| Github|申请友链|手机版|Code4App ( 粤ICP备15117877号-1 )

快速回复 返回顶部 返回列表