清除UISearchBar的文本框背景
UIImage *searchImg = [UIImage imageNamed:@"seach_top_bk"]; searchImg=[searchImg resizableImageWithCapInsets:UIEdgeInsetsMake(20, 20, 20, 20) resizingMode:UIImageResizingModeStretch];//拉伸背景图片 _searchBar = [[UISearchBar alloc]initWithFrame:CGRectMake(115, 7,200 , 30)]; _searchBar.backgroundImage =searchImg;// 背景图片 _searchBar.delegate = self; _searchBar.showsCancelButton = NO; _searchBar.placeholder = @"输入关键字.."; for (UIView * subView in _searchBar.subviews) { if ([subView isKindOfClass:[UITextField class]]) { UITextField * field = (UITextField *) subView; field.borderStyle = UITextBorderStyleNone; field.background = nil; //将UISearchBar的UITextField的背景清除掉 } }