4

I have a very simple page in my storyboard to create/edit a note. It's a basic ViewController, and the only content of the view is a UITextField for the title of the note, and a UITextView for the body of it, positioned right below.

Both the body field and the title field use the default label color, as well as the default white background (which should switch to black in dark mode). I'm completely lost as to why the UITextField does not switch automatically. Am I missing something about these elements? Screenshot below:

enter image description here

OstrichGlue
  • 325
  • 1
  • 4
  • 13
  • what's the iOS version you are testing ? and Xcode version ? – Rakshitha Muranga Rodrigo Dec 13 '19 at 16:16
  • @RakshithaMurangaRodrigo iOS 13.1.3, Xcode 11.1 – OstrichGlue Dec 13 '19 at 16:17
  • 1
    Xcode 11.1 has been banned to use from apple it self. Actually I came across the similar scenario with that version. Please upgrade your Xcode into 11.2.1, but lately released a new Xcode version too.. Upgrade and see... if issue is consistent let me know.. we will try it then.. – Rakshitha Muranga Rodrigo Dec 13 '19 at 16:21
  • Actually Xcode 11.3 was released 3 days ago. You should upgrade to that and see if you problem persists. – Andrew Dec 13 '19 at 16:41
  • What do you mean by "default white background"? Because if you set it to `.white` it _won't_ change in dark mode. You need to use one of the system colors (e.g., `. systemBackground`) to have it automatically change. – Frank Rupprecht Dec 14 '19 at 09:12
  • UITextField textcolor is set to labelColor, but not changing to white in dark mode. Is UITextField dark mode not supported yet ? – neobie May 10 '20 at 06:22

1 Answers1

2

The default value of this property is UIUserInterfaceStyle.unspecified, which causes the view to inherit the interface style from a parent view or view controller. If you assign a different value, the new style applies to the view and all of the subviews owned by the same view controller.

if #available(iOS 13.0, *) {
        txtUsername.overrideUserInterfaceStyle = .light
    } else {
        // Fallback on earlier versions
    }
thevikasnayak
  • 559
  • 5
  • 13
  • 3
    Please describe what your answer accomplishes. [How do I write a good answer](https://stackoverflow.com/help/how-to-answer) – sushibrain Jan 04 '21 at 09:29
  • @thevikasnayak This answer will not help out, because this will ignore the dark mode. we need the answer to switch the mode while switch the dark/light mode. Can you guide about that? – Muhammad Danish Qureshi May 20 '22 at 06:00