gpt4 book ai didi

ios - Active UISearchBar 使状态栏背景变黑

转载 作者:可可西里 更新时间:2023-11-01 06:15:01 24 4
gpt4 key购买 nike

我在 UITableView 的顶部有一个 UISearchBar,效果很好。我一直在尝试自定义它的外观,但当搜索栏处于事件状态时出现问题 - 它会将状态栏背景颜色变为黑色。我尝试了 IOS7 Status bar change to black after search is active 中的建议但它对我不起作用。

Example showing the black status bar

应用仅适用于 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 的颜色相匹配。

谢谢!

最佳答案

这是我用来扩展 UISearchBar 颜色的小 hack

在 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];
}
}
}

关于ios - Active UISearchBar 使状态栏背景变黑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24473116/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com