views:

516

answers:

2

When the keyboard appears, I want to set the

keyboardAppearance = UIKeyboardAppearanceAlert

I've checked the documentation and it looks like you can only change the keyboardType.

Can this be done without violating any of Apple's private API's ?

A: 

keyboardAppearance is a property of the UITextInputTraitsProtocol, which means that the property is set via the TextField object. I'm not aware of what an Alert Keyboard is, from the SDK it's a keyboard suitable for an alert.

here's how you access the property:

UITextField *myTextField = [[UITextField alloc] init];
myTextField.keyboardAppearance = UIKeyboardAppearanceAlert;

Now when the user taps the text field and the keyboard shows up, it should be what you want.

JustinXXVII
You missed the fact that this is coming from a UISearchBar and not a UITextField.The UIKeyboardAppearanceAlert has a transparent background, which I want to keep the same throughout all of my app. This can be achieved as you have demonstrated on UITextFields, however the UISearchBar also has a text field inside it. I wanted to know if it is possible to set the keyboard appearance for this text field.
iphone_developer
My bad. In the docs, it looks like there isn't a property or method to set keyboard transparency on the UISearchBar class. You can only set keyboard type.
JustinXXVII
+2  A: 

This should do it:

for(UIView *subView in searchBar.subviews)
    if([subView isKindOfClass: [UITextField class]])
        [(UITextField *)subView setKeyboardAppearance: UIKeyboardAppearanceAlert];

didn't find any other way of doing...

Damien