UI 日期选择器范围。 iPhone

发布于 2024-11-26 13:06:14 字数 945 浏览 0 评论 0原文

我有一个 datePickerView,我希望它有一个最小日期 = 当前时间,最大日期 = 48 小时后。它目前工作正常,因为我无法在该范围内进行选择。但存在一些审美问题。该范围内的某些时期不是黑色的。例如,在下图中,今天的 7 小时指针应该是黑色的,但事实并非如此。

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);


}

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);


}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不顾 2024-12-03 13:06:14

当您设置最小日期和最大日期时,这是默认行为,并且 APPLE 会明确执行此操作以表明它们不可选。

您可以做的是为日期实现 UIPickerView 并为 pickerView 方法实现 viewForRow

- (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.

}

您还可以更改 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 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文