views:

3411

answers:

6

Hi,

I'm trying to set the background color of a UITableViewCell to transparent. But nothing seems to work. I have some images/buttons inside the tableViewCell and I would like to make the white grouptableview background dissapear to get a 'floating' effect for the images and buttons (as if they were not inside the tableview).

Any idea how this could be accomplished?

A: 
viewCell.contentView.backgroundColor = [UIColor clearColor];
monowerker
Just tried using this code after creating the cell, but it doesn't do anything. is there a specific place where it should be called?
levi
Should work, you need to make sure you don't have any opaque views in between you tableviewcells and whatever background you want to see.
monowerker
You can try setting tableView.backgroundColor = [UIColor redColor]; if you see the red, nothing is in the way...
monowerker
There might be a viewCell.backgroundView.backgroundColor you need to set to clearColor as well...
monowerker
set tableView to [UIColor redColor]; but the cell is still the default white. Setting the color of the cell seems to work with a color other than clearColor e.g.[UIColor blueColor] , but only if it's set later (not after the creation of the cell) in - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
levi
As described in the post below adding the content to the header or footer of the tableView solves the problem for my case..http://stackoverflow.com/questions/573987/displaying-uitableviewcells-side-by-side-on-the-same-row-as-in-contacts-info
levi
+1  A: 

Start with these articles to get the background correctly setup:

http://howtomakeiphoneapps.com/2009/03/how-to-add-a-nice-background-image-to-your-grouped-table-view/

http://pessoal.org/blog/2009/02/25/customizing-the-background-border-colors-of-a-uitableview/

Then try all the following lines:

[[cell contentView] setBbackgroundColor:[UIColor clearColor]];
[[cell backgroundView] setBbackgroundColor:[UIColor clearColor]];
[cell setBbackgroundColor:[UIColor clearColor]];

There is more than just one view hiding in a UITableViewCell. This should make all of the ones in your way clear.

Corey Floyd
works perfectly...except one typo: setBbackgroundColor =>setBackgroundColor
Michael Z
+17  A: 

If both the other options didn't work try this

UIView *backView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
backView.backgroundColor = [UIColor clearColor];
cell.backgroundView = backView;
Ron Srebro
Thanks a lot! This solution is perfect!
levi
myTable.backgroundColor = [UIColor clearColor]; worked for me! Thanks
sjobe
This worked for me as well, although I additionally had to use:cell.backgroundColor = [UIColor clearColor];
Mirko Froehlich
I had to use cell.textLabel.backgroundColor=[UIColor clearColor] too!
Casebash
+1  A: 

I had a problem where my custom tableviewcell backgroundimage was overlaid with a white label background, i tried everything and finally setting background to clear color in the viewWillAppear did the trick.

      - (void)viewWillAppear:(BOOL)animated
    {
[super viewWillAppear:animated];
    self.tableView.backgroundColor = [UIColor clearColor]; // if this is not here, cell background image is covered with a white rectangle :S
    }

and in the rowForCellAtIndexPath I set the background image:

 if(!cell) {
 cell = [[[UITableViewCell alloc] initWithFrame: ...
 UIImageView *cellBG = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"cellbg.jpg"]];
 [cell setBackgroundView:cellBG];
 [cellBG release];
}
texmex5
+1  A: 

You can look at a short tutorial I wrote about Creating Unique Looking Table with Custom Cells that may provide some insight.

John

iPhoneDevTips

John
+1  A: 

This is actually answered in the docs of UITableViewCell. So while you do have to setup transparency on your controls, the actual cell background color must be set per below.

"Note: If you want to change the background color of a cell (by setting the background color of a cell via the backgroundColor property declared by UIView) you must do it in the tableView:willDisplayCell:forRowAtIndexPath: method of the delegate and not in tableView:cellForRowAtIndexPath: of the data source. Changes to the background colors of cells in a group-style table view has an effect in iOS 3.0 that is different than previous versions of the operating system. It now affects the area inside the rounded rectangle instead of the area outside of it."

EDIT: adding link

http://developer.apple.com/library/ios/#documentation/uikit/reference/UITableViewCell_Class/Reference/Reference.html

logancautrell