![](/img/trans.png)
[英]How to Dynamically Change UIImageView color in tableviewcell in Swift?
[英]How to change tableViewCell background color
注意:这是关于GROUPED tableView中的单元格 。 与普通的tableView相比,这有很大的不同! 默认的单元格自定义答案在这种情况下不起作用,因此请先验证您的答案。
这是我设置灰色屏幕和黄色tableView背景的方式:
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor grayColor];
UIView *myView = [[UIView alloc] initWithFrame:magicRect];
myView.backgroundColor = [UIColor yellowColor];
[self.tableView addSubview:myView];
[self.tableView sendSubviewToBack:myView];
}
这就是我设置绿色单元格背景的方式。 从图片中可以看到,它缺少一些区域:
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell =
[tableView dequeueReusableCellWithIdentifier:@"Cell"];
if (cell == nil) {
cell = [[[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleValue1
reuseIdentifier:@"Cell"] autorelease];
cell.backgroundColor = [UIColor greenColor];
}
// Configure the cell...
}
问题:如何在tableView单元格的开头和结尾更改颜色 ? 现在,该单元格在这些区域中是透明的,并在整个tableView下方显示self.view.backgroundColor。 这些区域实际上是透明的,因为在滚动tableView时,带纹理的背景保持在同一位置。
像这样将tableView背景设置为清晰的颜色,
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView setBackgroundColor:[UIColor clearColor]];//Here you can give as yellow instead of adding view
//ur code
}
我不知道为什么要向表视图添加子视图,可以为表视图设置背景颜色:
tview.backgroundColor=[UIColor yellowColor];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.