Monday, 2 September 2013

Removing the image on the left of an UISearchbar

.h file
@interface Search : UIViewController<UISearchBarDelegate>
{
IBOutlet UISearchBar *searchBar;
}
.m file
@interface Search (Private)
- (void)setSearchIconToFavicon;
@end
@implementation Search
- (void)viewDidLoad {
[self setSearchIconToFavicon];
[super viewDidLoad];
}
#pragma mark Private
- (void)setSearchIconToFavicon {
// Really a UISearchBarTextField, but the header is private.
UITextField *searchField = nil;
for (UIView *subview in searchBar.subviews) {
if ([subview isKindOfClass:[UITextField class]]) {
searchField = (UITextField *)subview;
break;
}
}
if (searchField) {
UIImage *image = [UIImage imageNamed: @"favicon.png"];
UIImageView *iView = [[UIImageView alloc] initWithImage:image];
searchField.leftView = iView;
[iView release];
}
} 
@end

No comments:

Post a Comment