iOS 日期选择器,允许用户选择日期。
只需将 MZDayPicker 库文件添加到您的项目中,并在 storyboard 中设置 MZDayPicker 和 IBOutlet 到您的控制器,以遵循 MZDayPicker 代理来接收回调。
@property (weak, nonatomic) IBOutlet MZDayPicker *dayPicker;
您可以使用当前月份设置选择器。
- (void)viewDidLoad
{
[super viewDidLoad];
self.dayPicker.month = 9;
self.dayPicker.year = 2013;
self.dayPicker.delegate = self;
self.dayPicker.dayNameLabelFontSize = 7.0f;
self.dayPicker.dayLabelFontSize = 15.0f;
[self.dayPicker setActiveDaysFrom:1 toDay:30];
[self.dayPicker setCurrentDay:15 animated:NO];
}
您还可以设置开始和结束日期范围。
- (void)viewDidLoad
{
[super viewDidLoad];
...
[self.dayPicker setStartDate:[NSDate dateFromDay:28 month:9 year:2013] endDate:[NSDate dateFromDay:5 month:10 year:2013]];
[self.dayPicker setCurrentDate:[NSDate dateFromDay:3 month:10 year:2013] animated:NO];
}
实现可选的原型方法,在选择新的日期项时接收通知。
- (void)dayPicker:(MZDayPicker *)dayPicker willSelectDay:(MZDay *)day
{
NSLog(@"Will select day %@",day.day);
}
- (void)dayPicker:(MZDayPicker *)dayPicker didSelectDay:(MZDay *)day
{
NSLog(@"Did select day %@",day.day);
[self.tableData addObject:day];
[self.tableView reloadData];
}
@protocol MZDayPickerDataSource <NSObject>
@optional
- (NSString *)dayPicker:(MZDayPicker *)dayPicker titleForCellDayLabelInDay:(MZDay *)day;
- (NSString *)dayPicker:(MZDayPicker *)dayPicker titleForCellDayNameLabelInDay:(MZDay *)day;
@end
@protocol MZDayPickerDelegate <NSObject>
@optional
- (void)dayPicker:(MZDayPicker *)dayPicker scrollViewDidScroll:(UIScrollView *)scrollView;
- (void)dayPicker:(MZDayPicker *)dayPicker scrollViewDidEndDecelerating:(UIScrollView *)scrollView;
- (void)dayPicker:(MZDayPicker *)dayPicker scrollViewDidEndDragging:(UIScrollView *)scrollView;
- (void)dayPicker:(MZDayPicker *)dayPicker willSelectDay:(MZDay *)day;
- (void)dayPicker:(MZDayPicker *)dayPicker didSelectDay:(MZDay *)day;
@end
/*
* Font colors (optional)
*/
@property (nonatomic, strong) UIColor *activeDayColor;
@property (nonatomic, strong) UIColor *activeDayNameColor;
@property (nonatomic, strong) UIColor *inactiveDayColor;
/*
* Picker background color (optional)
*/
@property (nonatomic, strong) UIColor *backgroundPickerColor;
/*
* Property for cell footer color (optional)
*/
@property (nonatomic, strong) UIColor *bottomBorderColor;
/* Day number and name font size (optional) */
@property (nonatomic, assign) CGFloat dayLabelFontSize;
@property (nonatomic, assign) CGFloat dayNameLabelFontSize;
/* Day number zoom scale (optional) */
@property (nonatomic, assign) CGFloat dayLabelZoomScale;
@property (nonatomic, readonly) CGSize dayCellSize;
@property (nonatomic, readonly) CGFloat dayCellFooterHeight;
MZDayPicker 需要iOS 5.x 或更高版本。
MZDayPicker 支持Storyboard。
MZDayPicker 使用ARC。