0
votes

I'm trying to give the cells in my grouped UITableView a semi-transparent image as their background. I've tried so many different ways but can't seem to get it to work. This is what I've got so far:

-(void) viewWillAppear:(BOOL) animated{
[super viewWillAppear:animated];
self.table.backgroundColor = [UIColor clearColor];}

.

-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{


UIImage *cellBackground;
NSInteger sectionRows = [tableView numberOfRowsInSection:[indexPath section]];
NSInteger row = [indexPath row];


if (row == 0)
{
    cellBackground = [UIImage imageNamed:@"tCT.png"];
}

else if (row == sectionRows -1)
{
    cellBackground = [UIImage imageNamed:@"tableCellBottom.png"];
}

else
{
    cellBackground = [UIImage imageNamed:@"tableCellMiddle.png"];
}

cell.backgroundColor = [UIColor clearColor];
UIView *cellBackView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
cellBackView.backgroundColor = [UIColor colorWithPatternImage: cellBackground];
cell.backgroundView = cellBackView; 

So at the moment the image shows up, but it's transparency isn't obvious. The background is a solid grey (rather than a semi-transparent grey). There are also black corners on the rounded group-table corners.

Any idea where I'm going wrong?

1
Is you image already transparent ? Because if not, you have to set the imageView alpha. - Ludovic Landry
The image is definitely transparent. I created it in Photoshop, exported for Web&Devices and ticked 'transparency'. The transparency shows up fine in Finder's QuickLook. - Luke

1 Answers

0
votes

set the backgroundColor of your cell's contentView to clearColor to remove the black borders.

self.contentView.backgroundColor = [UIColor clearColor];