step1
新增一個日期選擇器
MyPickerView *datePickerView;
step2
datePickerView = [MyPickerView getDatePickerViewWithBarForController:self title:@"select time" ];
datePickerView.datePickerView.datePickerMode = UIDatePickerModeDateAndTime;
datePickerView.datePickerView.maximumDate = [NSDate date];
[datePickerView.datePickerView addTarget:self action:@selector(dateChanged:) forControlEvents:UIControlEventValueChanged];
設定最大日期不能超過今天
step3
因為ios6 在秒上沒有處理得很好
再加上dateChanged的方法來處理
-(void)dateChanged:(UIDatePicker*)sender
{
if([sender.date compare:sender.minimumDate] == NSOrderedSame)
{
NSDate* oneSecondAfterPickersDate = [sender.date dateByAddingTimeInterval:1] ;
[sender setDate:oneSecondAfterPickersDate animated:YES];
}
}
0 意見:
張貼留言