Fre*_*ddy 13 objective-c uisearchbar ios ios7
我目前正在开发一款在ios7出现之前工作正常的应用程序.搜索栏过去是透明的,并混合到导航栏的蓝色背景中.现在我在ios7中工作,导航栏是蓝色的,但是搜索栏有灰色背景.如何将其设为蓝色或透明?
这是一张图片:

Qua*_* Hà 35
试试这个:
if(IOS_7)
{
self.searchBar.searchBarStyle = UISearchBarStyleMinimal;
}
Run Code Online (Sandbox Code Playgroud)
Dav*_*las 12
You can set "Bar Tint" to "Clear Color" in Interface Builder (.xib):

It can also be done in code:
self.searchBar.barTintColor = [UIColor clearColor];
Run Code Online (Sandbox Code Playgroud)
要使其变为平面颜色,只需删除UISearchBarBackground视图即可.
我创建了一个递归方法来正确清理搜索栏.
- (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];
}
}
}
Run Code Online (Sandbox Code Playgroud)
您只需将搜索栏发送到方法并随后更改颜色即可.
[self removeUISearchBarBackgroundInViewHierarchy:self.searchDisplayController.searchBar];
self.searchDisplayController.searchBar.backgroundColor = yourUIColor;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
21968 次 |
| 最近记录: |