简体   繁体   English

如何为UITableView和UISearchBar创建透明背景

[英]How to create Transparent background for UITableView and UISearchBar

In my application i added one UITableView and UISearchBar and its background by default white color. 在我的应用程序中,我添加了一个UITableViewUISearchBar及其默认背景为白色。 I would like to change the background of both items to clear or transparent, For that i tried to change the background colors . 我想将两个项目的背景都更改为透明或透明,为此,我尝试更改了背景色。

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

But its not affect on UI. 但它不会影响UI。 How to do it properly? 怎么做呢?

The UI screenshot given bellow . UI屏幕截图如下。

在此处输入图片说明

For TableView 对于TableView

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

And asign clear color to cell 并为单元格分配清晰的颜色

cell.backgroundColor = [UIColor clearColor];

And for UISearchBar 对于UISearchBar

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

For iOS7+, all you need to do is: 对于iOS7 +,您需要做的是:

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

as written in Make UISearchBar background clear 使UISearchBar背景清晰可见

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM