如果,UITableView的类型为UITableViewStyleGrounped,发现使用_tableView.backgroundColor = [UIColor clearColor]
后,tableView的背景色仍然是默认的色,上网查了下:
_tableView.backgroundView = nil;
可以搞定。
测试下发现确实可以,但是不知道以前的版本不确定有没有backgroundView的,所以最好加个判断吧:
1 2 3 4
| if (mainTableView.backgroundView) { mainTableView.backgroundView =nil; }
|
如果类型为UITableViewStylePlain,[UIColor clearColor]仍然有效,怪哉!
正常情况下grouped样式(UITableViewStyleGrouped)UITableViewCell都是有边框的,如果要去掉边框可以用:
1 2 3
| UIView *tempView = [[[UIView alloc] init] autorelease]; [cell setBackgroundView:tempView]; [cell setBackgroundColor:[UIColor clearColor]];
|
其实很简单,把backgroundView设置为一个空的View,然后就干净了。看了下UITableViewCell的文档,backgroundView在plain-style的TableView里面是nil,在grouped-style的TableView里面并不是空的,所以这里设置空就ok了,这是目前为止我见到的最完美的解决方案。
1
| [tableView setSeparatorColor:[UIColor clearColor]];
|
1
| cell.backgroundView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
|