Objective C :
NSArray *searchBarSubViews = [[self.searchBar.subviews objectAtIndex:0] subviews];
for (UIView *view in searchBarSubViews) {
if([view isKindOfClass:[UITextField class]])
{
UITextField *textField = (UITextField*)view;
UIImageView *imgView = (UIImageView*)textField.leftView;
imgView.image = [imgView.image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
imgView.tintColor = [UIColor whiteColor];
UIButton *btnClear = (UIButton*)[textField valueForKey:@"clearButton"];
[btnClear setImage:[btnClear.imageView.image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forState:UIControlStateNormal];
btnClear.tintColor = [UIColor whiteColor];
}
}
[self.searchBar reloadInputViews];
Swift :
// Text field in search bar.
let textField = searchController.searchBar.valueForKey("searchField") as! UITextField
let glassIconView = textField.leftView as! UIImageView
glassIconView.image = glassIconView.image?.imageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate)
glassIconView.tintColor = UIColor.whiteColor()
let clearButton = textField.valueForKey("clearButton") as! UIButton
clearButton.setImage(clearButton.imageView?.image?.imageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate), forState: .Normal)
clearButton.tintColor = UIColor.whiteColor()