vilelam
vilelam

Reputation: 804

UITableViewCell Background Image - Ipad Development

I would like to define a background like the attached image to my UITableViewCell. I’m trying that with the code below but without success.

cell.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"teste1.png"]];

My UITableView is a grouped and static one. I've also tried to define tableView.backgroundcolor to clear color but also without success.

Any help will be appreciated. Thanks, Marcos

UITableViewCellBackground

enter image description here

Upvotes: 0

Views: 404

Answers (3)

Master Stroke
Master Stroke

Reputation: 5128

Try this...

cell.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"YOUR_IMAGE.png"]];

Upvotes: 1

vilelam
vilelam

Reputation: 804

I end up placing a UIButton inside the whole UITableViewCell area.

Upvotes: 0

onevcat
onevcat

Reputation: 4631

In the Apple's UITableViewCell documation, about backgroundView:

The default is nil for cells in plain-style tables (UITableViewStylePlain) and non-nil for grouped-style tables UITableViewStyleGrouped). UITableViewCell adds the background view as a subview behind all other views and uses its current frame location.

So I don't think it would be a good idea to change the backgroundView for a grouped-style tables (which is happened your situation). Try to insert a new imageView above the back ground view:

UIImage *background = [UIImage imageWithContentsOfFile:@"teste1"];
UIImageView *cellBackgroundView = [[UIImageView alloc] initWithImage:background];
[cell insertSubview:cellBackgroundView aboveSubview:cell.backgroundView];

And don't forget to set the color to clear in all views may be above and block the background.

Upvotes: 0

Related Questions