lev*_*evi 71 iphone cocoa-touch uitableview
我正在尝试将a的背景颜色设置UITableViewCell
为透明.但似乎没有任何效果.我内部有一些图像/按钮tableViewCell
,我想让白色grouptableview
背景消失,以获得图像和按钮的"浮动"效果(好像它们不在里面tableview
).
知道如何实现这一目标吗?
Ron*_*bro 123
如果其他选项都不起作用,请尝试此操作
UIView *backView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
backView.backgroundColor = [UIColor clearColor];
cell.backgroundView = backView;
Run Code Online (Sandbox Code Playgroud)
log*_*ell 42
这实际上是在UITableViewCell的文档中回答的.因此,虽然您必须在控件上设置透明度,但必须在下面设置实际的单元格背景颜色.
"注意:如果要更改单元格的背景颜色(通过UIView声明的backgroundColor属性设置单元格的背景颜色),则必须在tableView:willDisplayCell:forRowAtIndexPath:委托方法中执行此操作,而不是tableView:cellForRowAtIndexPath:数据源.对于组样式表视图中单元格的背景颜色的更改在iOS 3.0中具有与以前版本的操作系统不同的效果.它现在影响圆角矩形内的区域它外面的区域."
https://developer.apple.com/documentation/uikit/uitableviewcell
Cor*_*oyd 30
从这些文章开始,以正确设置背景颜色:
http://pessoal.org/blog/2009/02/25/customizing-the-background-border-colors-of-a-uitableview/
然后尝试以下所有行:
[[cell contentView] setBackgroundColor:[UIColor clearColor]];
[[cell backgroundView] setBackgroundColor:[UIColor clearColor]];
[cell setBackgroundColor:[UIColor clearColor]];
Run Code Online (Sandbox Code Playgroud)
UITableViewCell中隐藏的视图不止一个.这应该使你所有的方式都清楚.
小智 26
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
cell.backgroundColor = [UIColor clearColor];
cell.backgroundView.backgroundColor = [UIColor clearColor];
}
Run Code Online (Sandbox Code Playgroud)
Muh*_*Ali 19
我有一个简单的解决方案
Objective-c版本:
cell.backgroundColor = [UIColor clearColor];
Run Code Online (Sandbox Code Playgroud)
Swift版本:
cell.backgroundColor = UIColor.clearColor()
Run Code Online (Sandbox Code Playgroud)
Mar*_*ian 11
默认情况下,UITableViewCell的背景为白色.做myCell.backgroundColor = [UIColor clearColor];
会使你的UITableViewCell透明但是你不会感觉到区别,因为默认情况下UITableView(你的UITableViewCell的竞争对手)也有白色背景.
如果你想看到你的UIView背景,你必须让你的细胞和你的桌子背景透明:
myTableView.backgroundColor = [UIColor clearColor];
myTableCell.backgroundColor = [UIColor clearColor];
Run Code Online (Sandbox Code Playgroud)
马丁马加基安