使用DIDatepicker
https://github.com/noxt/DIDatepicker
效果:
#import "DIViewController.h"
#import "DIDatepicker.h"
@interface DIViewController ()
@property (weak, nonatomic) IBOutlet DIDatepicker *datepicker;
@property (weak, nonatomic) IBOutlet UILabel *selectedDateLabel;
@end
@implementation DIViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// 给DIDatepicker添加了相应事件
[self.datepicker addTarget:self
action:@selector(updateSelectedDate)
forControlEvents:UIControlEventValueChanged];
// 当前月
[self.datepicker fillCurrentMonth];
[self.datepicker selectDateAtIndex:0];
}
- (void)updateSelectedDate
{
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
formatter.dateFormat = [NSDateFormatter dateFormatFromTemplate:@"EEEEddMMMM"
options:0
locale:nil];
self.selectedDateLabel.text = \
[formatter stringFromDate:self.datepicker.selectedDate];
}
@end
源码其实很恶心......
DIDatepicker继承至UIControl,而UIControl继承至UIView
红色线条是在DIDatepicker.m中的drawRect:方法中动态绘制的,有着修改的余地:)
至于修改字体颜色之类的,是在DIDatepickerDateView.m中(我简单的将星期六星期天修改成了红色)
他的这种设计其实还是很合理的:)
时间: 2024-10-27 14:22:37