Changing UIKeyboardAppearance

Hello,

I'm showing a keyboard in my textview and would like to change the appearance of the keyboard after its been displayed.


textView.keyboardAppearance = colorTheme == .classic ? .default : .dark


But it looks like the appearance can only be set before the keyboard is shown.


Is there a way to change the appearnce after the keyboard has appeared?


Please let me know.


Ramon.

Accepted Reply

I tested in simulator.


Change occurs after resignFirstResponder().


So you can switch with the following:


          let previousAppearance = theTextField.keyboardAppearance.rawValue
      
          theTextField.resignFirstResponder()
          theTextField.keyboardAppearance = UIKeyboardAppearance(rawValue: (previousAppearance+1) % 4) ?? .default
          theTextField.becomeFirstResponder()

Replies

I tested in simulator.


Change occurs after resignFirstResponder().


So you can switch with the following:


          let previousAppearance = theTextField.keyboardAppearance.rawValue
      
          theTextField.resignFirstResponder()
          theTextField.keyboardAppearance = UIKeyboardAppearance(rawValue: (previousAppearance+1) % 4) ?? .default
          theTextField.becomeFirstResponder()

Thank you!


I tried something similar and didn't but its because I have to handle my textview delegates a bit more intelligently.