UIDatePicker 更改“今天"文本的颜色日期 [英] UIDatePicker Change color of text of "today" date

查看:55
本文介绍了UIDatePicker 更改“今天"文本的颜色日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这个问题在其他时候也有人提出过,但是使用 xCode 7 和 iOS9.2 是否可以更改 UIDatePicker 上今天"日期的字体颜色?

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.

我还有其他选择吗,或者我真的需要构建自己的 DatePicker?

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

提前致谢.

推荐答案

通过更多的搜索,我找到了解决方案.

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.

这篇关于UIDatePicker 更改“今天"文本的颜色日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆