xcode 设置单元格的背景颜色不起作用 - IOS

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11772320/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 01:06:25  来源:igfitidea点击:

Setting background color of cell not working - IOS

iphoneobjective-ciosxcode

提问by Feroz

Possible Duplicate:
How to customize the background color of a UITableViewCell?

可能的重复:
如何自定义 UITableViewCell 的背景颜色?

I am trying to set the text color of a cell but it is not working. Here is the code..

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

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

Here selection style is working but text color not affecting. Any idea what I am doing wrong?

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

回答by Saurabh Passolia

Set the background color of contentViewlike this:

contentView像这样设置背景颜色:

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

回答by HelmiB

cell_center.textLabel.textColor = [UIColor redColor];

回答by Rick

You actually wanted to set your TEXT color but you did not even do that. Try this:

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

cell_center.textLabel.textColor = [UIColor blackColor];

回答by Baub

Looks like the other answers are showing how to change the cell background color, not the label background color.

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

To change the labelbackground color, use the following code.

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

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

Let me know if this doesn't work for you and we'll troubleshoot some more.

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