搜索栏中的iOS更改图标

我正在尝试自定义搜索栏。 我已经想出如何更改搜索栏中的背景和文本框,但我找不到更改栏中默认图标的方法(放大玻璃图标)。

有没有办法做到这一点?

开源是你的朋友(就像cocoa一样,呵呵):

- (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]; } } 

自iOS 5.0起:

 [self.testSearchBar setImage:[UIImage imageNamed: @"favicon.png"] forSearchBarIcon:UISearchBarIconSearch state:UIControlStateNormal]; 
 searchBar.setImage(UIImage(named: "tempUser")!, forSearchBarIcon: UISearchBarIcon.Search, state: UIControlState.Normal)