OGeek|极客世界-中国程序员成长平台

标题: ios - 更改 datePicker 线条和字体颜色 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 22:19
标题: ios - 更改 datePicker 线条和字体颜色

有人知道如何更改 UIDatePicker 的线条和字体颜色并避免使用私有(private) Apple api 吗? 我找到了这个,但它是非常肮脏的解决方案:

        datePicker.setValue(UIColor.white, forKey: "textColor")

        for subview in self.datePicker.subviews {

            if subview.frame.height <= 5 {

                subview.backgroundColor = UIColor.white
                subview.tintColor = UIColor.white
                subview.layer.borderColor = UIColor.white.cgColor
                subview.layer.borderWidth = 0.5            }
        }

        if let pickerView = self.datePicker.subviews.first {

            for subview in pickerView.subviews {

                if subview.frame.height <= 5 {

                    subview.backgroundColor = UIColor.white
                    subview.tintColor = UIColor.white
                    subview.layer.borderColor = UIColor.white.cgColor
                    subview.layer.borderWidth = 0.5
                }
            }
            self.datePicker.setValue(UIColor.white, forKey: "textColor")
        }



Best Answer-推荐答案


试试这个:

enter image description here

按代码或:

datePicker.setValue(UIColor.red, forKeyPath: "textColor")

关于ios - 更改 datePicker 线条和字体颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55005425/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4