title: Is there a way to tell iOS to update the keyboard appearance within a view controller?
body: <p>I'd like to update the <code>UIKeyboardAppearance</code> within a <code>ViewController</code>. By this I mean let's say the VC loads with <code>UIKeyboardAppearance.default</code>. If I press a button, I'd like the keyboard to update to <code>.dark</code> and have the keyboard now show in that same VC as <code>.dark</code>.</p>
  
  <p>As far as I can tell, iOS checks the value for <code>UIKeyboardAppearance</code> while loading the VC, and doesn't check again until it loads the VC again. Even if you change the value of <code>UIKeyboardAppearance</code> and hide/show the keyboard. </p>
  
  <pre><code>import UIKit
  
  class ViewController: UIViewController {
  
      override func viewDidLoad() {
          super.viewDidLoad()
  
  // creating a simple text box, and making the placeholder text the value of the keyboardAppearance
          myTextBox.backgroundColor = UIColor.lightGray
          myTextBox.frame = CGRect(x: 30, y: 200, width: 300, height: 50)
          view.addSubview(myTextBox)
          UITextField.appearance().keyboardAppearance = .dark
          myTextBox.becomeFirstResponder()
          myTextBox.placeholder = "Keybaoard Appearance is: \(UITextField.appearance().keyboardAppearance.rawValue)"
  
  // a simple button to toggle the keyboardAppearance
          toggleButton.frame = CGRect(x: 30, y: 300, width: 300, height: 50)
          toggleButton.setTitle("Toggle Keyboard", for: .normal)
          toggleButton.backgroundColor = UIColor.red
          toggleButton.addTarget(self, action: #selector(toggleButtonFunction), for: .touchUpInside)
          view.addSubview(toggleButton)
  
      }
  
  // toggles the keyboardAppearance. Hides the keyboard, and a second later shows it again.
      @objc func toggleButtonFunction() {
          if UITextField.appearance().keyboardAppearance == .dark {
              UITextField.appearance().keyboardAppearance = .default
          }
          else {
              UITextField.appearance().keyboardAppearance = .dark
          }
          myTextBox.resignFirstResponder()
          DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(1), execute: {
              self.myTextBox.becomeFirstResponder()
              self.myTextBox.placeholder = "Keybaoard Appearance is: \(UITextField.appearance().keyboardAppearance.rawValue)"
  
              })
      }
  
      let myTextBox = UITextField()
      let toggleButton = UIButton()
  }
  </code></pre>
  
  <p>I was hoping that after changing the <code>UIKeyboardAppearance</code> and hiding/showing the keyboard it would show with the new appearance (<code>.dark</code> or <code>.default</code>), but it continually shows with the same appearance until the VC is loaded again. You can see the value of <code>UIKeyboardAppearance</code> changes, but iOS seems to not check for that update until the VC loads again. </p>
  
  <p>Is there any way to force a recheck within a VC?</p>
  
  <p>Thanks for your help!</p>