分组UITableView中的透明背景 - iPhone

Jac*_*cek 21 iphone transparency background uitableview

我想让分组的UITableView透明化.我部分成功使用以下代码:

UIColor *bgColor = [[UIColor alloc] initWithWhite:1 alpha:0.0];
historyTable.backgroundColor = bgColor;
Run Code Online (Sandbox Code Playgroud)

不幸的是,圆角单元格中出现黑角.如何摆脱它们?

之前http://i49.tinypic.com/2iaa05u.jpg 之后http://i45.tinypic.com/2cnvckk.jpg

Tom*_*ing 37

而不是使用

UIColor *bgColor = [[UIColor alloc] initWithWhite:1 alpha:0.0];
historyTable.backgroundColor = bgColor;
Run Code Online (Sandbox Code Playgroud)

只需使用:

historyTable.backgroundColor = [UIColor clearColor];
Run Code Online (Sandbox Code Playgroud)

这也清除了你正在创建的内存泄漏.

  • 注意:当前必须在代码中设置[UIColor clearColor],如果在Interface Builder中设置了clearColor,则它不起作用. (6认同)

小智 35

删除UITableView backgroundView

xxx.backgroundView = nil;
Run Code Online (Sandbox Code Playgroud)

这在iPad版本中是必需的.编译在iPad和iPhone上运行时,检查tableView是否响应选择器...

if ([self.tableView respondsToSelector:@selector(setBackgroundView:)]) {
    [self.tableView setBackgroundView:nil];
}
Run Code Online (Sandbox Code Playgroud)


zer*_*nna 8

对我来说,它设置为nil/clear之后最终完成了:

[myTableView setBackgroundView:nil];
[myTableView setBackgroundColor:[UIColor clearColor]];
Run Code Online (Sandbox Code Playgroud)