设置UISearchBar透明背景

当设置UIsearchBar的时候发现无论是通过
searchB.translucent = YES;
还是
searchB.backgroundColor = [UIColor clearColor];
都无法将searchBar的背景设置为透明的。
在StackOverFlow中发现了一个方法
for (UIView *subview in _searchB.subviews) {
for(UIView* grandSonView in subview.subviews){
if ([grandSonView isKindOfClass:NSClassFromString(@"UISearchBarBackground")]) {
grandSonView.alpha = 0.0f;
}else if([grandSonView isKindOfClass:NSClassFromString(@"UISearchBarTextField")] ){
NSLog(@"Keep textfiedld bkg color");
}else{
grandSonView.alpha = 0.0f;
}
}
}```
//简单粗暴的去除灰色背景