1
A
回答
4
东阳UI搜索栏已经得到了自己的背景来看,这是黑色的,如果我们删除该视图然后的UISearchBar的背景会变得清晰:
for (UIView *subview in mySearchBar.subviews) {
if ([subview isKindOfClass:NSClassFromString(@"UISearchBarBackground")]) {
[subview removeFromSuperview];
break;
}
}
-1
尝试用这一行:
[[ [searchBar subviews] objectAtIndex:0] removeFromSuperview];
[[ [searchBar subviews] objectAtIndex:0] setBackgroundColor:[UIColor yellowColor]];
肯定会帮助你。
2
//搜索栏(使用背景图片)
UISearchBar* bar = [[UISearchBar alloc] initWithFrame:CGRectMake(568, 30, 200, 44)];
UIImageView* iview = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"blue.png"]];
iview.frame = CGRectMake(0, 0, 200, 44);
[bar insertSubview:iview atIndex:1];
[iview release];
[self.view addSubview:bar];
[bar release];
OR(使用彩色)
//搜索栏
UISearchBar* bar = [[UISearchBar alloc] initWithFrame:CGRectMake(568, 30, 200, 44)];
[[[bar subviews] objectAtIndex:0] setAlpha:0.0];
bar.tintColor = [UIColor colorWithRed:.376f green:.386f blue:.452f alpha:1.0];
bar.clipsToBounds = YES;
[self.view addSubview:bar];
[bar release];
+0
Thnanks为您的答案 – SampathKumar 2013-03-25 14:32:56
0
清晰的背景颜色(如果您想要图像设置,然后使用评论代码)
for (UIView *subview in searchBar.subviews)
{
if ([subview isKindOfClass:NSClassFromString(@"UISearchBarBackground")])
{
// if You want set iamge then use comment code
/* UIView *backgroundView = [[UIView alloc] initWithFrame:subview.frame];
bg.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"searchBar"]];
[self.searchBar insertSubview:backgroundView aboveSubview:subview];*/
[subview removeFromSuperview];
}
}
0
对于清除搜索栏的背景视图:
[[[self.searchBar subviews] objectAtIndex:0] setHidden:YES];
for (id subview in self.searchBar.subviews) {
if ([subview isKindOfClass:NSClassFromString(@"UISearchBarBackground")]) {
[subview removeFromSuperview];
}
}
2
设置为的UISearchBar背景图片如下。
[searchBar setBackgroundImage:[UIImage new]];
现在UISearchBar背景色将消失。也可以在iOS 7.1中工作
+0
我发现这是最简单和最干净的解决方案。在iOS 8.1中工作。 – Alexander 2014-11-20 15:34:51
0
我在iOS8中发现,这可以更好地将UISearchBar简化为文本字段。这将允许您摆脱背景颜色。
for (UIView *subView in self.searchBar.subviews) {
for (UIView *secondLevelSubview in subView.subviews) {
if (![secondLevelSubview isKindOfClass:NSClassFromString(@"UISearchBarTextField")]) {
[secondLevelSubview removeFromSuperview];
}
}
}
相关问题
- 1. 如何为GridViewColumn设置背景颜色
- 2. 如何更改搜索栏后面的背景颜色
- 3. Qt:如何设置QPushButton的背景颜色为系统颜色?
- 4. Angular4背景颜色设置
- 5. 设置VIM背景颜色
- 6. 设置背景颜色toolbaritems
- 7. 设置背景颜色CMDIFrameWnd
- 8. 设置行背景颜色
- 9. 设置背景颜色
- 10. TreeCellRenderer:如何设置背景颜色?
- 11. 如何设置背景颜色?
- 12. 如何设置tableView的背景颜色
- 13. 如何设置AlertDialog背景颜色
- 14. 如何设置JQGRID行背景颜色?
- 15. 如何设置UIWebView的背景颜色
- 16. 如何设置RelativeLayout背景颜色?
- 17. 如何设置标签背景颜色
- 18. 如何设置UIWebView的背景颜色?
- 19. 如何设置Canvas3D背景颜色?
- 20. 如何设置Qtextedit背景颜色?
- 21. 如何设置角度md-工具栏背景颜色
- 22. 设置背景颜色为XSLFO
- 23. 为UIView设置背景颜色
- 24. 为EKEventEditViewController设置背景颜色/图像
- 25. 将背景颜色设置为DotNet.Highcharts
- 26. 为div设置背景颜色
- 27. 为Panorama标题设置背景颜色
- 28. 将背景颜色设置为页面
- 29. 为对话框标题栏设置背景颜色?
- 30. 搜索字形的背景颜色
它只是创造黑色的背景,我需要显示导航背景颜色 – Hiren 2012-03-20 06:00:46
我改变了我的答案后..我检查它在我的代码...现在它工作正常... – 2012-03-20 06:23:03
是否searchDisplayControllers内这项工作?我不能让这与iOS 6.1工作 – powerj1984 2013-06-13 17:43:01