Reputation: 804
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
Upvotes: 0
Views: 404
Reputation: 5128
Try this...
cell.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"YOUR_IMAGE.png"]];
Upvotes: 1
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