开发者

changing the background color of custom cell

开发者 https://www.devze.com 2023-01-20 02:42 出处:网络
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.

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;
0

精彩评论

暂无评论...
验证码 换一张
取 消