Open-source is your friend (such as cocoa is, huh):
- (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]; } }
Since iOS 5.0:
[self.testSearchBar setImage:[UIImage imageNamed: @"favicon.png"] forSearchBarIcon:UISearchBarIconSearch state:UIControlStateNormal];
source share