Reputation: 7370
I'm trying to customise the UISearchBar
in my current app without much success. What I am trying to do is this:
However the end result is this:
You see in the second image I still have the original search icon there. I have not been able to find a way to remove it all together. I thought setting a custom background image would solve it, but evidently, not.
Edit: The suggested duplicate question mentioned doesn't solve the problem. Non the provided code works in removing the icon.
Edit 2:
This is how I have added the background image, which contains the orange icon on the left
[self.searchBar setSearchFieldBackgroundImage:[UIImage imageNamed:@"search_bar"] forState:UIControlStateNormal];
Upvotes: 1
Views: 601
Reputation: 6611
The following works for me on iOS 8+:
[mySearchBar setImage:[UIImage imageNamed:@"SearchBarIcon"] forSearchBarIcon:UISearchBarIconSearch state:UIControlStateNormal];
Upvotes: 1
Reputation: 4271
Even though the answer exists HERE, it does not work with iOS >= 7.x. The following will:
for (UIView *subView in self.searchedBar.subviews) {
for (UIView *subView2 in subView.subviews) {
if ([NSStringFromClass([subView2 class]) isEqualToString:@"UISearchBarTextField"]) {
UITextField *searchField = (UITextField *)subView2;
searchField.leftViewMode = UITextFieldViewModeNever;
}
}
}
Upvotes: 1