将UITableView背景颜色设置为透明的方法

最近在使用UITableView做页面的时候,被一个问题困扰很久,如何将UITableView的页面的背景颜色设置为透明,

显示效果为:每个TableView的Cell只显示图片,lbl等内容,但背景色为透明,即显示为其所在的的UIView的背景色。

在百度上搜索了很多方法都无效,今天终于解决:

一直在纠结于UITableView和UITableViewCell的背景色设置为透明,但无效,最终发现,需要设置一下UITableViewCell的

一个lableText的backgroundcolor为透明色,这样问题就迎刃而解了,具体代码很简单:

//    这里使用编写一个简单地例子
//    iTableView为UITableView的一个实例j
//    Cell为自定义UITableViewCell的一个实例

//  将tableView背景色设置为透明
    iTableView.backgroundView = nil;
    iTableView.backgroundColor = [UIColor clearColor];
//  将cell和cell.textLabel的背景色全都设置为透明 
   cell.textLabel.backgroundColor = [UIColor clearColor];
   cell.backgroundColor = [UIColor clearColor];
//    使用自己定义的背景色
self.view.backgroundColor = [UIColor ...];
//    或者为UITableView设置一个背景色,两者效果是有区别的,请选择需要的方案
iTableView.backgroundColor = [UIColor ...];

 效果图(TableView使用所在的UIView的颜色作为背景色):

posted @ 2014-05-12 22:06  晨星、风  阅读(1183)  评论(0编辑  收藏  举报