我试图设置一个 uidatepicker 来预订日历中的一些活动。我需要在我的 UIDatePicker 中禁用(隐藏)某些特定日期,例如我出城或度假的日子。
你能帮我解决这个问题吗?提前感谢很多。这是一些代码:
- (void)viewDidLoad
{
NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"IT"];
[self.datePicker setLocale:locale];
NSString *min = @"20132015";
NSString *max = @"22132015";
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"ddMMyyyy HH:mm"];
NSDate *datemin = [dateFormat dateFromString:min];
NSDate *datemax = [dateFormat dateFromString:max];
[self.view addSubview:datePicker];
datePicker.minuteInterval = 15;
datePicker.maximumDate = datemax;
datePicker.minimumDate = [NSDate date];
[datePicker addTarget:self action:@selector(disableDate) forControlEvents:UIControlEventValueChanged];
[datePicker addTarget:self
action:@selector(LabelChange:)
forControlEvents:UIControlEventValueChanged];
[super viewDidLoad];
// Do any additional setup after loading the view.
}
-(void)disableDate{
NSDate *pickedDate = datePicker.date; // Get current Date
NSDate *disabledDate = [?????;
if([pickedDate compare:disabledDate] == NSOrderedSame)
{
[datePicker setDate:disabledDate animated:YES];
}
}
-(void)getDisableDate
{
?????
}
- (void)LabelChange:(id)sender{
NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateFormat:@"dd.MM.yyyy HH:mm"];
NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"IT"];
[self.datePicker setLocale:locale];
labelDate.text = [NSString stringWithFormat:@"%@",
[df stringFromDate:datePicker.date]];
NSLog(@"date:%@", datePicker.date);
}