UI 日期选择器范围。 iPhone
我有一个 datePickerView,我希望它有一个最小日期 = 当前时间,最大日期 = 48 小时后。它目前工作正常,因为我无法在该范围内进行选择。但存在一些审美问题。该范围内的某些时期不是黑色的。例如,在下图中,今天的 7 小时指针应该是黑色的,但事实并非如此。
- (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);
}
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.
- (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);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您设置最小日期和最大日期时,这是默认行为,并且 APPLE 会明确执行此操作以表明它们不可选。
您可以做的是为日期实现
UIPickerView
并为 pickerView 方法实现viewForRow
。您还可以更改 pickerView 中值的字体大小。
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 implementviewForRow
for the pickerView methods.You can also change the font size of the values in the pickerView.