简体   繁体   中英

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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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