ios - 为什么在选择日期之前 UIDatePicker 的颜色设置不会激活?

标签 ios swift xcode colors uidatepicker

我可以更改文本的颜色和背景颜色,但这些更改只有在我选择日期并点击“开始”按钮后才可见。有没有一种方法可以在应用程序启动后立即使颜色更改生效。这是发生问题的视频... https://www.youtube.com/embed/GlA0LIYC1VU

这是我的代码:

    @IBOutlet weak var dateWheel: UIDatePicker!


@IBAction func goButton(_ sender: UIDatePicker) {

    dateWheel.backgroundColor = .blue
    dateWheel.setValue(UIColor.white, forKeyPath: "textColor")

    let dateStringFormatter = DateFormatter()


    dateStringFormatter.dateFormat = "yyyy-MM-dd HH:mm:sss"
    dateStringFormatter.locale = Locale(identifier: "en_US_POSIX")

最佳答案

我必须移动 dateWheel.backgroundColor = .blue dateWheel.setValue(UIColor.white, forKeyPath: "textColor")

viewDidLoad 的内部

问题解决后。

Reddit 帮助我回答了这个问题 u/pkoddity

关于ios - 为什么在选择日期之前 UIDatePicker 的颜色设置不会激活?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40952734/

相关文章:

ios - xcode IOS swift NSURLConnection 工作缓慢

ios - xcodebuild 错误 : "requested but didn' t find extension point with identifier . ..”

ios - xcode Storyboard不适合 iphone 5

ios - Swift - 2个空字符串数组

ios - 什么时候应该使用导航 Controller ?

swift - 如何在 Swift 2.0 中使用 enumerateNodeWithName?

swift - 枚举、结构、类之间有什么区别

iphone - 在多台计算机上为 iOS 开发,在单个设备上测试,建议?

ios - MKMapView 中带有自定义精度圆的自定义用户位置标记

iphone - 我的 UIViewController 怎么知道是谁把它放到堆栈上的?