我在UISearchBar
的顶部有一个UITableView
,效果很好。我一直在尝试自定义其外观,当搜索栏处于活动状态时会出现问题 - 它会将状态栏背景颜色变为黑色。我尝试了IOS7 Status bar change to black after search is active中的建议,但它对我没用。
App仅限iOS 7。 UISearchBar
是最小搜索样式和默认栏样式,半透明和默认barTintColor。我已经在我的AppDelegate中自定义了它的外观,如下所示:
[[UISearchBar appearance] setBarTintColor:AAColorInputBorder];
[[UISearchBar appearance] setBackgroundColor:AAColorInputBorder];
[[UILabel appearanceWhenContainedIn:[UISearchBar class], nil] setTextColor:[UIColor whiteColor]];
[[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setTextColor:[UIColor whiteColor]];
[[UIBarButtonItem appearanceWhenContainedIn:[UISearchBar class], nil]
setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor],NSForegroundColorAttributeName,
[UIFont fontWithName:@"Avenir" size:16], NSFontAttributeName,
nil] forState:UIControlStateNormal];
[[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setFont:[UIFont fontWithName:@"Avenir" size:14]];
有没有人知道如何更改状态栏背景颜色?我希望它与UISearchBar
的颜色相匹配。
谢谢!
答案 0 :(得分:0)
这是我用来扩展UISearchBar颜色的一点点黑客
在viewDidLoad()
上if ([self respondsToSelector:@selector(edgesForExtendedLayout)])
self.edgesForExtendedLayout = UIRectEdgeNone;
[self removeUISearchBarBackgroundInViewHierarchy:self.searchDisplayController.searchBar];
方法:
- (void) removeUISearchBarBackgroundInViewHierarchy:(UIView *)view {
for (UIView *subview in [view subviews]) {
if ([subview isKindOfClass:NSClassFromString(@"UISearchBarBackground")]) {
[subview removeFromSuperview];
break; //To avoid an extra loop as there is only one UISearchBarBackground
} else {
[self removeUISearchBarBackgroundInViewHierarchy:subview];
}
}
}