I would really like to change the color of the "Search" button on the keyboard to match the theme of my app. But if that is not possible, at least I would like to do
self.searchBar.keyboardAppearance = UIKeyboardAppearanceDark;
But that does not work because, as I guess, the searchBar is not a UITextField. So how might I do this successful? I mean, change the color of the "Search" on the keyboard: whether fully or just the dark theme.
For iOS 8 use
self.searchBar.keyboardAppearance = UIKeyboardAppearance.Dark
Try this, it works with IOS 6 , IOS 7 and IOS 8:
[self setKeyboardOnSearchBar:self.searchBar];
And the function:
-(void)setKeyboardOnSearchBar:(UISearchBar *)searchBar
{
for(UIView *subView in searchBar.subviews) {
if([subView conformsToProtocol:@protocol(UITextInputTraits)]) {
[(UITextField *)subView setKeyboardAppearance:UIKeyboardAppearanceAlert];
[(UITextField *)subView setReturnKeyType:UIReturnKeySearch];
} else {
for(UIView *subSubView in [subView subviews]) {
if([subSubView conformsToProtocol:@protocol(UITextInputTraits)]) {
[(UITextField *)subSubView setReturnKeyType:UIReturnKeySearch];
[(UITextField *)subSubView setKeyboardAppearance:UIKeyboardAppearanceAlert];
}
}
}
}
}
Try the following
for(UIView *subView in self.searchBar.subviews) {
if([subView conformsToProtocol:@protocol(UITextInputTraits)]) {
[(UITextField *)subView setKeyboardAppearance: UIKeyboardAppearanceDark];
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With