【问题标题】:Setting background color of cell not working - IOS [duplicate]设置单元格的背景颜色不起作用 - IOS [重复]
【发布时间】:2012-07-31 02:54:00
【问题描述】:

可能重复:
How to customize the background color of a UITableViewCell?

我正在尝试设置单元格的文本颜色,但它不起作用。这是代码..

cell_center.backgroundColor = [UIColor redColor];
cell_center.textLabel.backgroundColor = [UIColor grayColor];
cell_center.selectionStyle = UITableViewCellSelectionStyleGray;

这里的选择样式有效,但文本颜色不受影响。知道我做错了什么吗?

【问题讨论】:

  • @HelmiB 不是那样,我只问了几个问题,我得到了正确答案的一两个问题,剩下的对我没有用。现在在这里它的工作感谢。 :)

标签: iphone objective-c ios xcode


【解决方案1】:

您实际上想设置 TEXT 颜色,但您甚至没有这样做。试试这个:

cell_center.textLabel.textColor = [UIColor blackColor];

【讨论】:

    【解决方案2】:
    cell_center.textLabel.textColor = [UIColor redColor];
    

    【讨论】:

    • 你应该接受一个你认为对你有帮助的答案。
    【解决方案3】:

    像这样设置contentView的背景颜色:

    [cell_center contentView].backgroundColor = [UIColor redColor];
    

    【讨论】:

      【解决方案4】:

      看起来其他答案正在显示如何更改单元格背景颜色,而不是标签背景颜色。

      要更改标签背景颜色,请使用以下代码。

      [cell_center.textLabel setBackgroundColor:[UIColor grayColor]];
      

      如果这对您不起作用,请告诉我,我们会解决更多问题。

      【讨论】:

      • 我认为他已经使用了这个他说不起作用。
      • 首先更正您的问题,您需要什么?
      • 您是否尝试设置文本颜色?如果是这样,请尝试[cell_center.textLabel setTextColor:[UIColor grayColor]];
      猜你喜欢
      • 2018-06-15
      • 1970-01-01
      • 1970-01-01
      • 2010-11-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-08
      相关资源
      最近更新 更多