ios - 更改 datePicker 行和字体颜色

标签 ios swift xcode customization uidatepicker

有谁知道如何更改 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")
        }

最佳答案

试试这个:

enter image description here

或按代码:

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

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

相关文章:

ios - SWIFT - 如何在显示 UIAlertController 消息后更改它

ios - 未调用行的 TableView 的委托(delegate)方法单元格

xcode - 无法在终端 macOS 10.15.7 上安装 cocoapods

c# - MonoTouch.Dialog:在后台设置 StyledStringElement 图像

c# - 如何在可移植类库中使用 wcf 服务并想在 xamarin 中的共享项目(我正在使用 Xamarin.Forms Portable)中添加引用?

ios - 多个获取请求?

ios - 一次可以选择两次的自定义选择器

ios - UITableView contentOffset 行为异常

ios - : "Property type "JSQMessagesCollectionView"is incompatible with type "UICollectionView",继承自 "UICollectionViewLayout"是什么意思

xcode - 如何禁用 "Multiple methods named ... found with mismatched result, parameter type or attributes"