我正在使用以下代码来隐藏 UISearchBar 上的背景: [[searchView.subviews objectAtIndex:0] setHidden:YES]; 很简单,但我担心对子视图列表中的位置进行硬编码。所以我去寻找 UISearchBarBackground.h 文件并找不到它。有谁知道定义隐藏在哪里?
问问题
3042 次
4 回答
5
其他方式:
for (UIView* subview in searchControl.subviews) {
if ([NSStringFromClass([subview class]) isEqualToString:@"UISearchBarBackground"]) {
[subview removeFromSuperview];
}
}
于 2011-09-01T13:16:28.233 回答
0
要简单地在 [subView isKindOfClass:[UISearchBarBackground class]] 中使用,以下工作就可以了:
@interface UISearchBarBackground : NSObject { } @end
更完整的定义可在 github 上找到。
于 2010-04-28T17:46:25.727 回答
0
对于ios4它没有用,所以我试试这个,它可以工作
[[self.mySearchBar.subviews objectAtIndex:0] removeFromSuperview];
于 2010-07-09T10:05:05.600 回答
0
您可以使用 NSClassFromString() 方法来避免创建一个新类来测试相等性
for (UIView *v in [self.searchbar subviews]) {
if ([v isKindOfClass:NSClassFromString(@"UISearchBarBackground")]) {
// whatever you want to do with the subview goes here...
}
}
于 2013-09-05T21:07:15.310 回答