您好,登錄后才能下訂單哦!
本篇文章給大家分享的是有關(guān)怎么在iOS中自定義一個(gè)日期選擇器,小編覺(jué)得挺實(shí)用的,因此分享給大家學(xué)習(xí),希望大家閱讀完這篇文章后可以有所收獲,話(huà)不多說(shuō),跟著小編一起來(lái)看看吧。
.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í)間類(lèi)型
typedef enum{ DateTypeStartDate, DateTypeEndDate }XHDateType; //設(shè)置是時(shí)間類(lèi)型 @property (nonatomic,assign)XHDateType dateType;
DateTypeStartDate:開(kāi)始時(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),返回開(kāi)始時(shí)間和結(jié)束時(shí)間)
-(instancetype)initWithCompleteBlock:(void(^)(NSDate *,NSDate *))completeBlock;
具體使用代碼
XHDatePickerView *datepicker = [[XHDatePickerView alloc] initWithCompleteBlock:^(NSDate *startDate,NSDate *endDate) { NSLog(@"\n開(kāi)始時(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];
以上就是怎么在iOS中自定義一個(gè)日期選擇器,小編相信有部分知識(shí)點(diǎn)可能是我們?nèi)粘9ぷ鲿?huì)見(jiàn)到或用到的。希望你能通過(guò)這篇文章學(xué)到更多知識(shí)。更多詳情敬請(qǐng)關(guān)注億速云行業(yè)資訊頻道。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。