更改日期选择器的文本颜色 [英] Changing text color of datepicker

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

问题描述

有没有办法在iOS8中改变datepicker的文本颜色?我知道在 iOS7 及更早版本中是不可能的,在第 8 个版本中发生了什么变化?

Is it any way to change text color of datepicker in iOS8? I've that it isn't possible in iOS7 and prior, something changed in 8th version?

例如,我在 Yahoo Weather 中发现了修改过的选择器!

For example I've found modified picker in Yahoo Weather!

推荐答案

在 stackoverflow 的评论中找到了解决方案.如果你只需要将文本颜色更改为您的颜色并将此子类分配给您的选择器.因为 whiteColor 就像魔法一样.

Found solution at comments of stackoverflow. If you need just to change text color to yours and assign this subclass you your picker. For whiteColor works as magic.

只有减去我发现所选数字的两行颜色仍然是灰色的.

Only minus i've found that color two lines of selected number is still gray.

class ColoredDatePicker: UIDatePicker {
    var changed = false
    override func addSubview(view: UIView) {
        if !changed {
            changed = true
            self.setValue(UIColor.whiteColor(), forKey: "textColor")
        }
        super.addSubview(view)
    }
}

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

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