Bourne
Bourne

Reputation: 10302

uitableviewcell custom background issue

I have a grouped tableview where I have one row in each section. I am setting the backgroundview of the cell to my custom image and I wish the row is rendered this way:

enter image description here

But it renders like this (notice the absence of shadows, it's flat):

enter image description here

Here's the code in cellforRowAtIndexPath:

((UIImageView *)cell.backgroundView).image = [UIImage imageNamed:@"BGImage"];

Where BGImage is the first image in this post, with shadows. What am I missing here?

Upvotes: 0

Views: 194

Answers (2)

Rushi
Rushi

Reputation: 4500

  1. Your shadow must be a part of your image.
  2. You have to properly set the height and width.
  3. I'd suggest you to create a custom UITableViewCell.
  4. Add background image to your cell. It'll surely display the shadow.

Upvotes: 0

Nitin Gohel
Nitin Gohel

Reputation: 49710

you have to set Your Cell Background using bellow Delegate Method of UITableView:-

- (void)tableView: (UITableView*)tableView
  willDisplayCell: (UITableViewCell*)cell
forRowAtIndexPath: (NSIndexPath*)indexPath
{
            UIImage *img = [UIImage imageNamed:@"yourImage.png"];  // get your background image
            UIColor *backgroundColor = [[UIColor alloc] initWithPatternImage: img];
            cell.backgroundColor = backgroundColor;
            cell.textLabel.backgroundColor = [UIColor clearColor];
            cell.detailTextLabel.backgroundColor = [UIColor clearColor]; 

}

at your issue may be your image Height width and your cell height width not same

I am using above method in my project set with bellow shaded image set in Cell:-

enter image description here

and its look like in project :-

enter image description here

Upvotes: 4

Related Questions