iOS實(shí)現(xiàn)自定義日期選擇器示例
iOS自定義日期選擇器,下面只是說(shuō)明一下怎么用,具體實(shí)現(xiàn)請(qǐng)?jiān)谧詈笙螺d代碼看看;
效果如下:
.h文件解析
選擇日期選擇器樣式
typedef enum{ DateStyleShowYearMonthDayHourMinute = 0, DateStyleShowMonthDayHourMinute, DateStyleShowYearMonthDay, DateStyleShowMonthDay, DateStyleShowHourMinute }XHDateStyle; //日期選擇器樣式 @property (nonatomic,assign)XHDateStyle datePickerStyle;
DateStyleShowYearMonthDayHourMinute :顯示年月日時(shí)分
DateStyleShowMonthDayHourMinute : 顯示月日時(shí)分(年份在底部顯示)
DateStyleShowYearMonthDay :顯示年月日
DateStyleShowMonthDay :顯示月日(年份在底部顯示)
DateStyleShowHourMinute :顯示時(shí)分
設(shè)置時(shí)間類型
typedef enum{ DateTypeStartDate, DateTypeEndDate }XHDateType; //設(shè)置是時(shí)間類型 @property (nonatomic,assign)XHDateType dateType;
DateTypeStartDate:開始時(shí)間
DateTypeEndDate :結(jié)束時(shí)間
設(shè)置最大最小時(shí)間限制
@property (nonatomic, retain) NSDate *maxLimitDate;//限制最大時(shí)間(沒(méi)有設(shè)置默認(rèn)2049) @property (nonatomic, retain) NSDate *minLimitDate;//限制最小時(shí)間(沒(méi)有設(shè)置默認(rèn)1970)
init對(duì)象(completeBlock 是點(diǎn)擊確定后的回調(diào),返回開始時(shí)間和結(jié)束時(shí)間)
-(instancetype)initWithCompleteBlock:(void(^)(NSDate *,NSDate *))completeBlock;
具體使用代碼
XHDatePickerView *datepicker = [[XHDatePickerView alloc] initWithCompleteBlock:^(NSDate *startDate,NSDate *endDate) { NSLog(@"\n開始時(shí)間: %@,結(jié)束時(shí)間:%@",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打印的時(shí)間會(huì)和實(shí)際時(shí)間相差8小時(shí),轉(zhuǎn)成字符串會(huì)打印出正確的時(shí)間。(因?yàn)镹SLog里,對(duì)時(shí)間的格式化是按GMT時(shí)間來(lái)轉(zhuǎn)的,GMT時(shí)間與北京時(shí)間相差8小時(shí))
demo下載:XHDatePicker_jb51.rar
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
IOS中UIImageView方法實(shí)現(xiàn)簡(jiǎn)單動(dòng)畫
這篇文章主要介紹了IOS中UIImageView方法實(shí)現(xiàn)簡(jiǎn)單動(dòng)畫的相關(guān)資料,需要的朋友可以參考下2017-05-05iOS實(shí)現(xiàn)MJRefresh下拉刷新(上拉加載)使用詳解
本篇文章主要介紹了iOS實(shí)現(xiàn)MJRefresh下拉刷新(上拉加載)使用詳解,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下。2017-01-01ios利用 AFN 上傳相冊(cè)或者拍照?qǐng)D片
這篇文章主要介紹了ios利用 AFN 上傳相冊(cè)或者拍照?qǐng)D片的相關(guān)資料,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2017-06-06移動(dòng)端固定輸入框在底部會(huì)被鍵盤遮擋的解決方法(必看篇)
下面小編就為大家分享關(guān)于移動(dòng)端固定輸入框在底部會(huì)被鍵盤遮擋的解決方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2017-12-12iOS之單獨(dú)使用UISearchBar創(chuàng)建搜索框的示例
本篇文章主要介紹了iOS之單獨(dú)使用UISearchBar創(chuàng)建搜索框的示例,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-10-10