carloabelli
carloabelli

Reputation: 4349

Setting the Background Color of a UITableViewCell to a Pattern Image

I have the follow code which sets the background of a UITableViewCell to a pattern image:

UIColor *color = [UIColor colorWithPatternImage:[UIImage imageNamed:@"TestPattern"]];
cell.backgroundColor = color;

This works and the background pattern is displayed, but the pattern overlaps strangely:

enter image description here

I think this is because the UITableViewCell is actually setting the background color of the labels and other views it contains along with its main view. How can I get the background color to not overlap?

Upvotes: 0

Views: 116

Answers (1)

matt
matt

Reputation: 535566

I think this is because the UITableViewCell is actually setting the background color of the labels

Correct, and very well explained. So you have to set the background color of the labels to clearColor separately. This is not entirely easy because, depending on the version of iOS, the runtime will try to set it back again for you; in iOS 4, for example, it was necessary to make this move in willDisplayCell, though in iOS 6 you can get away with doing it in cellForRow as long as you do it after setting the background color.

Upvotes: 2

Related Questions