UISearchBar remove background on iOS 4.1
I'm trying to remove the background of UISearchBar to make it transparent. I tried these solutions:
1.
for (UIView *subview in searchBar.subviews) {
if ([subview isKindOfClass:NSClassFromString(@"UISearchBarBackground")]) {
[subview removeFromSuperview];
break;
}
}
2.
[[searchBar.subviews objectAtIndex:0] rem开发者_开发知识库oveFromSuperview];
These two methods both work on iOS 4.3, but not on 4.1. it shows black. How can I make it work on iOS 4.1? I'm using SDK 4.3. Thanks.
This should work:
[[searchBar.subviews objectAtIndex:0] removeFromSuperview];
[searchBar setBackgroundColor:[UIColor clearColor]];
精彩评论