1

My problem:
I'm trying to develop a custom keyboard for iOS 8. I got the buttons working and all that, but I would like to know how to do the different setups whether it is an iPad or an iPhone, and how to change the appearance when the keyboard should be light or dark. Can I get a .xib for everything, or is there some kind of trick to it?

Example:
.xib for iPad Keyboard Portrait Light
.xib for iPad Keyboard Landscape Light
.xib for iPad Keyboard Portrait Dark
.xib for iPad Keyboard Landscape Dark
.xib for iPhone Keyboard Portrait Light
and so on and so forth...


I guess you could check the appearance of the keyboard this way, and then change the images of the buttons accordingly, but then the different keyboard on iPad for example (different layout) is my problem...

if (self.textDocumentProxy.keyboardAppearance == UIKeyboardAppearanceDark) {

Thanks in advance.

Andrew
  • 15,357
  • 6
  • 66
  • 101
ifraaank
  • 122
  • 2
  • 13

1 Answers1

0

You will want to change your keyboard theme by checking the keyboardAppearance in textDidChange(textInput: UITextInput). Just loop over all your buttons and apply the appropriate text/background colors.

I decided to use a single .xib file for my keyboard. You can optimize for iPad by using the Regular w Regular h size class but you can't optimize for iPhone in landscape because it's always the same in portrait (Compact w Compact h). So I have my keyboard set up in viewDidLayoutSubviews to detect the keyboard height and width, and then I use those values along with the trait collection size classes in order to optimize for those different screen sizes and orientations. You could also create many different xibs, I wouldn't recommend it if you can get away with a single xib.

Jordan H
  • 52,571
  • 37
  • 201
  • 351
  • Okay, thanks. I've managed to get the theme function working. But since i'm not familiar with size classes, I would like to have one .xib for iPhone, and one for iPad. Do you know how I can set that up, so that it loads them correctly? Thanks again. – ifraaank Sep 21 '14 at 15:51
  • In that case you'd need to load the appropriate xib conditionally based on the device size. You should be able to detect in `viewDidLoad` the size class (which will be Regular w Regular h only for iPad) and then load whichever xib is correct. If `viewDidLoad` is too early, you'd need to check later in the life cycle, at worst in `viewDidAppear`. You simply query `self.traitCollection.horizontalSizeClass` and `verticalSizeClass`. – Jordan H Sep 21 '14 at 19:29