RootViewController.m
#import "RootViewController.h"
@interface RootViewController ()
@property(nonatomic,strong)RootView * rv;
@end
@implementation RootViewController
-(void)loadView{
self.rv = [[RootView alloc]initWithFrame:[UIScreen mainScreen].bounds];
self.view = _rv;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
//样式
self.rv.datePicker.datePickerMode = UIDatePickerModeDate;
// self.rv.datePicker.datePickerMode = UIDatePickerModeCountDownTimer;
//国际化 显示中文日期 中文zh_CN 英文en_US
self.rv.datePicker.locale = [NSLocale localeWithLocaleIdentifier:@"zh_CN"];
//日历
self.rv.datePicker.calendar = [NSCalendar currentCalendar];
//时区
self.rv.datePicker.timeZone = [NSTimeZone timeZoneWithName:@"Asia/Shanghai"];
//时间格式
NSDateFormatter * dateFormatter = [[NSDateFormatter alloc]init];
[dateFormatter setDateFormat:@"yyyy"];
//最小时间
self.rv.datePicker.minimumDate = [dateFormatter dateFromString:@"2000"];
//最大时间
self.rv.datePicker.maximumDate = [dateFormatter dateFromString:@"2015"];
//当前表盘停留在哪个时间上
// self.rv.datePicker.countDownDuration = 60*60;
//
// //时间刻度
// self.rv.datePicker.minuteInterval = 3;
// NSLog(@"%@",[NSTimeZone,])
}
static int count = 0;
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
// 用触发的方式改变表盘上的值
// self.rv.datePicker.countDownDuration = count++ * 60;
// 获取表盘上的时间
NSLog(@"%@",self.rv.datePicker.date);
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
RootView.m
#import "RootView.h"
@implementation RootView
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self p_setupViews];
}
return self;
}
-(void)p_setupViews{
self.backgroundColor = [UIColor yellowColor];
self.datePicker = [[UIDatePicker alloc]initWithFrame:CGRectMake(0, 0, 100, 200)];
// 属性
// 样式
// self.datePicker.datePickerMode = UIDatePickerModeTime;
//
// self.datePicker.datePickerMode = UIDatePickerModeDate;
//
// self.datePicker.datePickerMode = UIDatePickerModeDateAndTime;
// self.datePicker.datePickerMode = UIDatePickerModeCountDownTimer;
// NSLog(@"%@",self.datePicker.locale);
// NSLog(@"%@",self.datePicker.date);
[self addSubview:_datePicker];
}