Reputation: 359
I am customizing my search bar with this but it is not showing any image. It remove its default image as well.
UITextField *searchField = nil;
for (UIView *subview in [[workLocationSearchBar.subviews lastObject] subviews]) {
NSLog(@"hey");
if ([subview isKindOfClass:[UITextField class]]) {
searchField = (UITextField *)subview;
NSLog(@"inside");
break;
}
}
if (searchField) {
UIView *searchIcon = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"circle.png"]];
if ([searchIcon isKindOfClass:[UIImageView class]]) {
}
NSLog(@"aye");
searchField.rightView = searchIcon;
searchField.leftView=searchIcon;
}
Upvotes: 0
Views: 361
Reputation: 1535
Try This:
[workLocationSearchBar setImage:[UIImage imageNamed:@"IMAGE_NAME"] forSearchBarIcon:UISearchBarIconSearch state:UIControlStateNormal];
Upvotes: 2