在-(void)viewDidLoad{}方法中添加如下代码:
for(id cc in [_searchBar subviews])
{
if([cc isKindOfClass:[UITextField class]])
{
UITextField *textField = (UITextField *)cc;
UIImage *image = [UIImage imageNamed:@"searchText.png"] ;
UIImageView *view = [[UIImageView alloc] initWithImage:image];
textField.leftView = view;
}
}