UI Datepicker range. iPhone

2020-04-20 07:15发布

I have a datePickerView which I want it to have a min date = current time, max date = 48hrs later. It's currently working fine, as I can't pick out of that range. But there's some aesthetic problems. Some of the period in that range is not in black. For example in the picture below, today's 7hour hand is suppose to be in black but its not.

pic

- (void)viewDidLoad 
{

[super viewDidLoad];
NSDate *now = [[NSDate alloc] init];
NSLog(@"now is %@", now);
[datepick setDate:now animated:YES];
[now release];
datepick.minimumDate = now;

NSDate *todaysDate = [NSDate date];
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *dateComponents = [[NSDateComponents alloc] init];
[dateComponents setHour:48];
NSDate *targetDate = [gregorian dateByAddingComponents:dateComponents toDate:todaysDate  options:0];
[dateComponents release];
[gregorian release];
datepick.maximumDate = targetDate;
NSLog(@"targetDate is %@", targetDate);


}

1条回答
相关推荐>>
2楼-- · 2020-04-20 07:44

This is default behavior when you set a minimum date and a maximum date and APPLE does it clearly to make it obvious that they are not selectable.

What you can do is implement a UIPickerView for the dates and implement viewForRow for the pickerView methods.

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{
UILabel* tView = (UILabel*)view;
if (!tView){
    tView = [[UILabel alloc] init];

    // Add label.text which is the picker value for the row (for that component)

    // set the font for the label as black.

}

You can also change the font size of the values in the pickerView.

查看更多
登录 后发表回答