views:

98

answers:

1

I have a UITableView and would like to apply a background image to all cells. My height for each cell is variable. How should I go about creating the background image?

cell.contentView.backgroundColor = [UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"background.png"]];
A: 

One idea is to place a UIImage with a stretchable image on it. That way, it doesn't matter what the row height is, the image can stretch to match.

You can also do something similar to what Matt has done here with a gradient layer

iWasRobbed
Can you describe the stretchable image? Will I need to create some 1x55 pixel (just an example) image and that will automatically stretch over the x-plane or is additional code needed?
Sheehan Alam
You basically just give an image and then tell it which parts aren't stretchable via `[[UIImage imageNamed: @"someBGImage.png"] stretchableImageWithLeftCapWidth:5 topCapHeight:5];` where the 5 pixels is the part that isn't stretchable (like a border). More info http://developer.apple.com/iphone/library/documentation/uikit/reference/UIImage_Class/Reference/Reference.html#//apple_ref/occ/instm/UIImage/stretchableImageWithLeftCapWidth:topCapHeight:
iWasRobbed