简体   繁体   English

更改自定义单元格的背景颜色

[英]changing the background color of custom cell

It looks simple thing but i dont know why i am not able to change the background color of a custom tag on which i am working. 它看起来很简单,但是我不知道为什么我不能更改正在使用的自定义标签的背景颜色。 Please check my code below for the custom cell. 请在下面检查我的代码以获取自定义单元格。

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {

    if ((self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])) {

        self.textLabel.backgroundColor = [UIColor clearColor];
        self.textLabel.textColor = [UIColor orangeColor];
        self.textLabel.text = @"lklklk";
        self.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        self.contentView.backgroundColor = [UIColor blackColor];
        self.accessoryView.backgroundColor = [UIColor blackColor];
    }

    return self;

}

The cell is only displaying the above text with white backgroud 单元格仅以白色背景显示上述文本

Thanks in advance 提前致谢

I've had to deal with this challenge myself while working on Spring Cleaning 在进行春季大扫除时,我不得不面对这个挑战

Here's how I solved the issue: 这是我解决问题的方法:

UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
view.backgroundColor = [UIColor blackColor];
view.opaque = YES;
self.backgroundView = view;
[view release];

UITableViewCells have a backgroundView which you need to hide in order to set the backgroundColor: UITableViewCells有一个backgroundView,您需要隐藏它以便设置backgroundColor:

[self.backgroundView setHidden:YES];
self.backgroundColor = [UIColor clearColor];
self.opaque = NO;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM