Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/112.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 将背景色设置为my UITableViewCell赢得';行不通_Ios_Uitableview_Background Color - Fatal编程技术网

Ios 将背景色设置为my UITableViewCell赢得';行不通

Ios 将背景色设置为my UITableViewCell赢得';行不通,ios,uitableview,background-color,Ios,Uitableview,Background Color,我有一个带有表视图的视图,是通过编程创建的(没有与XIB关联)。我希望一些单元格的背景颜色为浅灰色。 所以我试了一下: cell.contentView.backgroundColor = [UIColor colorWithRed:(230/255.f) green:(230/255.f) blue:(230/255.f) alpha:1.0]; 但结果是(问题当然是单元格的背景应该是完全灰色的): 我也试过了,结果和之前一样: UIView *cell_view = [[UIView a

我有一个带有表视图的视图,是通过编程创建的(没有与XIB关联)。我希望一些单元格的背景颜色为浅灰色。 所以我试了一下:

cell.contentView.backgroundColor = [UIColor colorWithRed:(230/255.f) green:(230/255.f) blue:(230/255.f) alpha:1.0];
但结果是(问题当然是单元格的背景应该是完全灰色的):

我也试过了,结果和之前一样:

UIView *cell_view = [[UIView alloc] init];
[cell_view setBackgroundColor:[UIColor colorWithRed:(230/255.f) green:(230/255.f) blue:(230/255.f) alpha:1.0]];
[cell setBackgroundView:cell_view];

似乎什么都不管用。谢谢你的帮助。

不要给背景颜色。而是创建具有所需颜色的视图。并设置为backgroundView。

覆盖
表视图:willDisplayCell:forRowAtIndexPath:
委托:

-(void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
    [cell setBackgroundColor:[UIColor colorWithRed:(230/255.f) green:(230/255.f) blue:(230/255.f) alpha:1.0]];
}
另外,将textLabel背景色设置为透明

cell.textLabel.backgroundColor = [UIColor clearColor];

将tableviews背景色设置为“清除颜色”

 tableView.backgroundColor = [UIColor clearColor];
请执行以下操作:

  • 将tableview背景色设置为“清除颜色”
  • 将cell.backgroundview设置为零
  • 将cell.backgroundcolor设置为灰色
  • 试试这个:

    //set this in viewDidLoad method
    yourTable.backgroundColor = [UIColor clearColor];
    
    //set this in cellForRowAtIndexPath method of UITableView
    cell.backgroundview = nil;
    cell.backgroundColor = [UIColor greenColor];
    

    这个代码是为我工作的

    请尝试以下代码:

    (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
    
    UIColor *CellColor = [UIColor colorWithRed:(230/255.f) green:(230/255.f) blue:(230/255.f) alpha:1.0];
    cell.backgroundColor = CellColor;
    

    }

    已经试过了,但没用(见更新的帖子)。谢谢你的回答。@Rob我很高兴能帮助你:)我试过这个解决方案,但也没用。谢谢您的回答。请尝试使用此单元格。backgroundColor=[UIColor redColor];