UISearchBarBackground Class
I am using the following piece of code to hide the background on a UISearchBar: [[searchView.subviews objectAtIndex:0] setHidden:YES]; Pretty simple, but I worry about hard coding a po开发者_如何学运维sition in a subview list. So I went looking for the UISearchBarBackground.h file and cannot find it. Does any know where the definition is hiding?
Another way:
for (UIView* subview in searchControl.subviews) {
if ([NSStringFromClass([subview class]) isEqualToString:@"UISearchBarBackground"]) {
[subview removeFromSuperview];
}
}
To simply use in [subView isKindOfClass:[UISearchBarBackground class]] the following works just fine:
@interface UISearchBarBackground : NSObject { } @end
A more complete definition is available at github.
For ios4 it didnt work, so I try this and it works
[[self.mySearchBar.subviews objectAtIndex:0] removeFromSuperview];
You can use NSClassFromString() method this instead to avoid having to create a new class just for testing equallity
for (UIView *v in [self.searchbar subviews]) {
if ([v isKindOfClass:NSClassFromString(@"UISearchBarBackground")]) {
// whatever you want to do with the subview goes here...
}
}
精彩评论