源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

iOS实现自定义日期选择器示例

  • 时间:2020-04-04 22:01 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:iOS实现自定义日期选择器示例
iOS自定义日期选择器,下面只是说明一下怎么用,具体实现请在最后下载代码看看; 效果如下: [img]http://files.jb51.net/file_images/article/201702/201727153944804.png?201717153955[/img] .h文件解析 选择日期选择器样式
typedef enum{
 DateStyleShowYearMonthDayHourMinute = 0,
 DateStyleShowMonthDayHourMinute,
 DateStyleShowYearMonthDay,
 DateStyleShowMonthDay,
 DateStyleShowHourMinute 
}XHDateStyle;
//日期选择器样式
@property (nonatomic,assign)XHDateStyle datePickerStyle;
DateStyleShowYearMonthDayHourMinute :显示年月日时分 [img]http://files.jb51.net/file_images/article/201702/201727154027380.png?201717154035[/img] DateStyleShowMonthDayHourMinute : 显示月日时分(年份在底部显示) [img]http://files.jb51.net/file_images/article/201702/201727154043943.png?201717154055[/img] DateStyleShowYearMonthDay :显示年月日 [img]http://files.jb51.net/file_images/article/201702/201727154105095.png?201717154113[/img] DateStyleShowMonthDay :显示月日(年份在底部显示) [img]http://files.jb51.net/file_images/article/201702/201727154122479.png?201717154132[/img] DateStyleShowHourMinute :显示时分 [img]http://files.jb51.net/file_images/article/201702/201727154143373.png?201717154151[/img] 设置时间类型
typedef enum{
 DateTypeStartDate,
 DateTypeEndDate 
}XHDateType;
//设置是时间类型
@property (nonatomic,assign)XHDateType dateType;
DateTypeStartDate:开始时间 DateTypeEndDate :结束时间 设置最大最小时间限制
@property (nonatomic, retain) NSDate *maxLimitDate;//限制最大时间(没有设置默认2049)
@property (nonatomic, retain) NSDate *minLimitDate;//限制最小时间(没有设置默认1970)
init对象(completeBlock 是点击确定后的回调,返回开始时间和结束时间)
-(instancetype)initWithCompleteBlock:(void(^)(NSDate *,NSDate *))completeBlock;
具体使用代码
  XHDatePickerView *datepicker = [[XHDatePickerView alloc] initWithCompleteBlock:^(NSDate *startDate,NSDate *endDate) {
    NSLog(@"\n开始时间: %@,结束时间:%@",startDate,endDate);
    self.startTimeText.text = [startDate stringWithFormat:@"yyyy-MM-dd HH:mm"];
    self.endtimeText.text = [endDate stringWithFormat:@"yyyy-MM-dd HH:mm"];
  }];
  datepicker.datePickerStyle = DateStyleShowYearMonthDayHourMinute;
  datepicker.dateType = DateTypeStartDate;
  datepicker.minLimitDate = [NSDate date:@"2017-08-11 12:22" WithFormat:@"yyyy-MM-dd HH:mm"];
  datepicker.maxLimitDate = [NSDate date:@"2020-12-12 12:12" WithFormat:@"yyyy-MM-dd HH:mm"];
  [datepicker show];
NSLog打印的时间会和实际时间相差8小时,转成字符串会打印出正确的时间。(因为NSLog里,对时间的格式化是按GMT时间来转的,GMT时间与北京时间相差8小时) demo下载:[url=http://xiazai.jb51.net/201702/yuanma/XHDatePicker_jb51.rar]XHDatePicker_jb51.rar[/url] 以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程素材网。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部