views:

158

answers:

1

I wanted to put a background image partially visible behind a list view. I created a list view in my nib with an image view behind it and made the list view background 20% opacity. This allows the background image to show thru but my text in the cells show a white background behind and if I create the cells in cellForRowAtIndexPath the cells have a white background too.

I am creating and setting the cell textLabel and the detailTextLabel in the cellForRowAtIndexPath event.

Not sure how to get rid of that, or if there is a better way to do the background image.

A: 

I had a similar issue and resolved it by setting the cell.contentView.backgroundColor to [UIColor clearColor] in cellForRowAtIndexPath.

If you did not want to make the whole cell transparent but the labels only, you can set the backgroundColor attribute of the textLabel and detailTextLabel to clear as well:

cell.textLabel.backgroundColor = [UIColor clearColor];

To set the background image of a table at run time rather than in a nib you can create a new UIColor from an image. Like so:

UIImage *img = [UIImage imageWithContentsOfFile: someFilePath];  // get your background image
UIColor *backgroundColor = [[UIColor alloc] initWithPatternImage: img];
[myTable setBackgroundColor: backgroundColor]; 
[backgroundColor release];
FredArters
Thanks! That worked.
MonkeyTroy
Sweet... good to hear.
FredArters