Change keyboard color for UISearchBar
I'd love to change the color of the Search button on my keyboard to match the theme of my application. But if it's not possible, at least I would like to do
self.searchBar.keyboardAppearance = UIKeyboardAppearanceDark;
But that doesn't work because as I assume searchBar is not a UITextField. So how can I do this successfully? I mean, change the "Search" color on your keyboard: full or just a dark theme.
+3
source to share
4 answers
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];
}
}
}
}
}
+5
source to share