【问题标题】:How to create Transparent background for UITableView and UISearchBar如何为 UITableView 和 UISearchBar 创建透明背景
【发布时间】:2016-08-09 14:01:09
【问题描述】:

在我的应用程序中,我添加了一个UITableViewUISearchBar,其背景默认为白色。我想将这两个项目的背景更改为清晰或透明,为此我尝试更改背景颜色。

tableview.tintColor=[UIColor clearColor];
srchbar.tintColor=[UIColor clearColor];

但它不会影响 UI。怎么做才合适?

用户界面截图如下。

【问题讨论】:

标签: ios objective-c uitableview uisearchbar


【解决方案1】:

对于表格视图

[self.yourtableView setBackgroundView:nil];
[self.yourtableView setBackgroundColor:[UIColor clearColor]];

并为单元格分配清晰的颜色

cell.backgroundColor = [UIColor clearColor];

对于 UISearchBar

[self.yourSearchBar setBackgroundColor:[UIColor clearColor]];
[self.yourSearchBarsetBackgroundImage:[UIImage new]];
[self.yourSearchBar setTranslucent:YES];

【讨论】:

  • 嘿......谢谢......通过使用你的代码我可以改变表格视图但搜索栏没有改变。它的背景本身是白色的......
  • 此更改是所有搜索栏的全局手段 [[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setBackgroundColor:[UIColor clearColor]];
【解决方案2】:

对于 iOS7+,您只需:

[self.searchBarHome setBackgroundColor:[UIColor clearColor]];
[self.searchBarHome setBarTintColor:[UIColor clearColor]]; //this is what you want

写在Make UISearchBar background clear

【讨论】:

  • 你想达到什么目的?将所有内容设为“红色”还是仅从搜索视图中删除“灰色叠加层”?
  • 我认为通过自动为所有控制器制作清晰的背景,它看起来像红色。
猜你喜欢
  • 2011-02-24
  • 1970-01-01
  • 2017-02-01
  • 2018-05-30
  • 1970-01-01
  • 2010-11-03
  • 1970-01-01
  • 1970-01-01
  • 2013-06-09
相关资源
最近更新 更多