直接上图:
灰色边框着实难看,设置一下searchBar的barTintColor:
_searchBar.barTintColor = [UIColor clearColor];
毫无用处!
再设置一下backgroundImage属性,backgroundImage有如下描述:
// 1pt wide images and resizable images will be scaled or tiled according to the resizable area, otherwise the image will be tiled
@property(nonatomic,retain) UIImage *backgroundImage NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;
设置它为透明图片:
_searchBar.backgroundImage = [self imageWithColor:[UIColor clearColor]];
- (UIImage *)imageWithColor:(UIColor *)color
{
CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextFillRect(context, rect);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
效果: