Search code examples
iosxcodeuidatepicker

UIDatePicker Change color of text of "today" date


I know that this question as been made other times, but with xCode 7 and iOS9.2 is it possible to change the font color of "today" date on a UIDatePicker?

[self.dpData setValue:[UIColor colorWithRed:111/255.0f green:113/255.0f blue:121/255.0f alpha:1.0f] forKeyPath:@"setHighlightsToday"];

I tried this and it crashed, so I know that this don't work.

Any other options that I have, or I really need to build my own DatePicker?

Thanks in advance.


Solution

  • With some more search I found the solution.

    [_dpData setValue:[UIColor colorWithRed:111/255.0f green:113/255.0f blue:121/255.0f alpha:1.0f] forKeyPath:@"textColor"];
    SEL selector = NSSelectorFromString( @"setHighlightsToday:" );
    NSInvocation *invocation = [NSInvocation invocationWithMethodSignature :
                                [UIDatePicker
                                 instanceMethodSignatureForSelector:selector]];
    BOOL no = NO;
    [invocation setSelector:selector];
    [invocation setArgument:&no atIndex:2];
    [invocation invokeWithTarget:_dpData];
    

    With this solution we can change the color of the text (even today date) without problems.