更改 UIDatePicker 字体颜色? [英] Change UIDatePicker font color?

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

问题描述

我想要做的就是更改 UIDatePicker 的字体颜色.我研究了其他问题,但它们都涉及更改其他属性和自定义整个外观.我想要做的只是将字体颜色从黑色更改为白色.我很难相信我做不到这么简单的任务.为什么色调颜色不会影响它?它甚至可以做任何事情吗?

All I want to do is change the font color of the UIDatePicker. I've researched other questions but they're all involving changing other properties and customizing the entire look. All I want to do is just change the font color from black to white. I find it hard to believe that I can't do such a seemingly simple task. And why wouldn't the tint color affect it? Does it even do anything?

推荐答案

我只需要(在 iOS 8.x 和 9.0 上)这一行来改变字体颜色:

All I need (on iOS 8.x and 9.0) is this one line to change the font color:

        [my_date_picker setValue:[UIColor whiteColor] forKey:@"textColor"];

没有子类化或调用私有 API...

No subclassing or invoking of private APIs...

注意:今天的当前日期仍将突出显示(在较新的 iOS 版本中).您可以使用以下代码解决此问题:

Note: today's current date will still be highlighted (in newer iOS versions). You can get around this by using the following code:

if ([my_date_picker respondsToSelector:sel_registerName("setHighlightsToday:")]) {

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wundeclared-selector"

        [my_date_picker performSelector:@selector(setHighlightsToday:) withObject:[NSNumber numberWithBool:NO]];

#pragma clang diagnostic pop

}

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

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