tags:

views:

22

answers:

2

Hi,

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

+1  A: 

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];
Jacob Relkin
thanks jacob for reply but it is not setting the background color for the complete cell. The accessory arrow is still having white background, which is not looking good, i need complete black background
pankaj
@pankaj, Try it now.
Jacob Relkin
tried that but still no success
pankaj
@pankaj, I've done this before, I'll go dig up the code.
Jacob Relkin
jacob, please check my updated code
pankaj
@pankaj, How about now?
Jacob Relkin
great jacob, it works, thanks a lot, can u please also help me in increasing the height of the cell from custom cell, i dont want to do it from my viewcontroller
pankaj
Ask that in another question and I'll be glad to answer it there. You shouldn't ask more questions in comments. Just ask another one.
Jacob Relkin
@pankaj, You should also accept the correct answers to your questions by clicking on the hollow checkmark and the up arrow. :)
Jacob Relkin
sure jacob, i have asked that in different question check it now..
pankaj
http://stackoverflow.com/questions/3952517/increasing-the-height-of-custom-cell
pankaj
A: 

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