【问题标题】:background for uitableview celluitableview 单元格的背景
【发布时间】:2017-06-29 06:39:17
【问题描述】:
MyTableCell *cell=[[MyTableCell alloc]init];
cell.backgroundColor = [UIColor clearColor];

以上几行代码仍然显示单元格背景为白色,并隐藏了tableview的背景图片。

【问题讨论】:

标签: ios objective-c uitableview


【解决方案1】:

转到您的故事板并设置您的 uitableview 单元格的颜色以从那里清除颜色。并且还将 uitabelview 颜色设置为清除颜色。

或者在你 viewdidload 中设置 tableview 背景颜色以清除颜色并在 cellforrow 中的 indexparth delagate 设置

cell.contentView.backGroundColor = [UIColor ClearColor]

【讨论】:

  • 请告诉我如何在表格视图中的两个单元格之间添加间隙?
  • 如果您想以编程方式执行此操作,则只需在您的单元格中为 indexpath 委托的行添加以下代码: UIView* separatorLineView = [[UIView alloc] initWithFrame:CGRectMake(0, 0,self.view .frame.size.width, 3)];/// 根据需要更改大小。 separatorLineView.backgroundColor = [UIColor blackColor];//这里也可以放图片 [cell.contentView addSubview:separatorLineView];
  • 会尝试并回复你
  • 我不想插入分隔线,我只想在它们之间留出间隙
  • 转到您的 Storyboard ,然后在您的 tableview 单元格中添加一个视图,在其中留下顶部和底部的间隙。根据需要使用间隙。然后在视图中添加所有控制器,如 label 、 button 等。如果需要,设置视图的边框。你会得到你想要的帽子。
【解决方案2】:

试试这个

- (void)tableView:(UITableView *)tableView willDisplayCell(UITableViewCell *)cellforRowAtIndexPath:(NSIndexPath *)indexPath
{
 [cell setBackgroundColor:[UIColor clearColor]];
}

【讨论】:

    【解决方案3】:

    同时设置 contentview 背景颜色

    cell.contentView.backGroundColor = [UIColor ClearColor];
    cell.backGroundView.backGroundColor = [UIColor ClearColor];
    cell.selectedBackGroundView.backGroundColor = [UIColor ClearColor];
    

    还要检查您是否还清除了tableView.backGroundColor

    【讨论】:

    • 这样做没有发生任何事情
    【解决方案4】:

    谢谢大家。我已经解决了这个问题。我将我的单元格对象的故事板的属性检查器中的背景属性从默认更改为清除颜色并且它起作用了。

    【讨论】:

    • 我认为您应该接受我的回答,因为我的解决方案是从情节提要中更改背景颜色。
    • 我不知道该怎么做。
    【解决方案5】:

    你可以这样做

    cell.backgroundColor = [UIColor clearColor];
    cell.backgroundView.backgroundColor = [UIColor clearColor];
    

    【讨论】:

    • 很抱歉,问题还是一样。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-11
    相关资源
    最近更新 更多