3 Replies
      Latest reply on Dec 6, 2019 10:49 AM by Jim Dovey
      DVMagic Level 1 Level 1 (0 points)

        This used to be possible to set the value for textColor key but I don't see how to do this within SwiftUI. Has anyone had any success with this or know how to set the appearance() global setting. Either works for me.



        • Re: DatePicker SwiftUI Text/Font color styling...
          Claude31 Level 8 Level 8 (7,255 points)

          Seems that .foregroundColor has no effect on a DatePicker.


          But that works for a picker:

          Picker(selection: $selectedColor, label: Text("color")) {
                             ForEach(0 ..< colors.count) {


          In Swift, you do it with:

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


          I don't know how to do it in SwiftUI.

          Looked here but did not yet figure out:

          h ttps://gist.github.com/AliSoftware/ecb5dfeaa7884fc0ce96178dfdd326f8

            • Re: DatePicker SwiftUI Text/Font color styling...
              DVMagic Level 1 Level 1 (0 points)

              Thanks Claude31. I live SwiftUI, but there are a bunch of places with complex UI's that it just isn't mature enough to completely convert over my existing project as a learning mechanism. I've had to make a few sacrifices to aesthetics. Hopefully, it will continue to be updated and over time will be a real IB replacement for most situations. Thanks for responding. I did use your answer in another place in code, so thank you and I hope this helps others.



              • Re: DatePicker SwiftUI Text/Font color styling...
                Jim Dovey Level 3 Level 3 (230 points)

                That UIDatePicker code looks suspiciously like it's accessing private state. Certainly `textColor` and `highlightsToday` aren't listed in the public API. Given that, it's unlikely you'll see those exposed by SwiftUI—private API will stay private.


                Also, while `setValue(_:forKey:)` won't crash, it may simply stop working at some point in the future, silently failing. Apple may even mark the version that takes a plain String for the key argument as unavailable from Swift. Such facilities can be useful, but you take on the burden of manually confirming the behavior remains the same on every single point release, because it could go away (or gain/lose side-effects) at any time.