1.建立繼承自upview這個檢視彈出類的時間選擇檢視類datepickerview,upview類的內容參照鏈結upview
#import "upview.h"
ns_assume_nonnull_begin
typedef ns_enum(nsinteger, datestyle);
@protocol datepickerviewdelegate -(void)didclicksurewithyear:(nsinteger )year andmonth:(nsinteger )month andday:(nsinteger)day;
@end
@inte***ce datepickerview : upview
//確定按鈕
@property (nonatomic, strong)uibutton *surebtn;
//取消按鈕
@property (nonatomic, strong)uibutton *cancelbtn;
//自定義選擇檢視
@property (nonatomic, strong)uipickerview *pickerview;
//系統選擇檢視
@property (nonatomic, strong)uidatepicker *datepicker;
//選擇的時間模式
@property (nonatomic, assign)datestyle datestyle;
//年,月,日
@property (nonatomic, assign)nsinteger year;
@property (nonatomic, assign)nsinteger month;
@property (nonatomic, assign)nsinteger day;
@property(nonatomic, weak)iddelegate;
@end
#import "datepickerview.h"
@inte***ce datepickerview()@end
@implementation datepickerview
/*// only override drawrect: if you perform custom drawing.
// an empty implementation adversely affects performance during animation.
- (void)drawrect:(cgrect)rect
*/- (instancetype)init
#pragma mark - 建立內容檢視
- (void)setcontentview else if (self.datestyle == datestyleyearandmonth)
}#pragma mark - 自定義選擇檢視
- (uipickerview *)pickerview
return _pickerview;
}#pragma mark - 系統時間檢視
- (uidatepicker *)datepicker
return _datepicker;
}#pragma mark - 系統時間選擇器變化
- (void)datechanged:(uidatepicker *)datepicker
#pragma mark - uipickerviewdelegate,uipickerviewdatasource
- (nsinteger)numberofcomponentsinpickerview:(uipickerview *)pickerview
- (nsinteger)pickerview:(uipickerview *)pickerview numberofrowsincomponent:(nsinteger)component else
}- (nsstring *)pickerview:(uipickerview *)pickerview titleforrow:(nsinteger)row forcomponent:(nsinteger)component else
}- (void)pickerview:(uipickerview *)pickerview didselectrow:(nsinteger)row incomponent:(nsinteger)component else
}#pragma mark - 確定按鈕
- (uibutton *)surebtn
return _surebtn;
}#pragma mark - 取消按鈕
- (uibutton *)cancelbtn
return _cancelbtn;
}#pragma mark -確定選擇
- (void)sureaction
}#pragma mark -重寫檢視出現的方法
- (void)show
[self setcontentview];
[[self lastwidow] addsubview:self];
[uiview animatewithduration:0.3 animations:^completion:^(bool finished) else if (self.datestyle == datestyleyearandmonth)
}];}#pragma mark - 獲取最上層window
- (uiwindow *)lastwidow
}}#pragma mark - 根據date獲取年月日
- (nsdatecomponents *)getyearandmonthanddayfrom:(nsdate *)date
@end
2.年月日選擇器使用方法:
datepickerview *datev = [[datepickerview alloc]init];
datev.contentheight = 300.0f;
datev.datestyle = datestyledate;
datev.delegate = self;
[datev show];
3.年月選擇器實現:
datepickerview *datev = [[datepickerview alloc]init];
datev.contentheight = 300.0f;
datev.datestyle = datestyleyearandmonth;
datev.delegate = self;
[datev show];
4.**
#pragma mark - datepickerviewdelegate
- (void)didclicksurewithyear:(nsinteger)year andmonth:(nsinteger)month andday:(nsinteger)day
jQuery年月日(生日)選擇器
我們在編輯使用者資料時經常會遇到選擇生日選項的問題,今天我給大家介紹如何使用js來實現年月日 生日 選擇器,能夠準確計算閏年的年月日,方便表單處理。html 生日中的年月日以下拉方式,我們給每個select加個rel屬性,當已知使用者生日日期的,直接通過rel屬性標註,外掛程式會將rel屬性值轉換成...
jq迴圈日期 jQuery年月日(生日)選擇器
html 生日中的年月日以下拉方式,我們給每個select加個rel屬性,當已知使用者生日日期的,直接通過rel屬性標註,外掛程式會將rel屬性值轉換成select的值。生日 年月日 載入jquery庫和選擇器外掛程式 jquery 我們將選擇器封裝成jquyer外掛程式的形式,只需使用以下方式呼叫...
年月日選擇器,選中行變成不同的色彩和字型大小
pragma mark pickview的相關方法 nsinteger numberofcomponentsinpickerview uipickerview pickerview nsinteger pickerview uipickerview pickerview numberofrowsin...