So I m trying to make a UITableView that has a repeating background. I want the background to scroll with the text. The catch is that the background is 2 images. There is a top image that is about 550px in height, and then a repeater image that s 2px in height. I want the top image to scroll with the table view and then eventually go off the top and then the segment image just repeats. This view actually sits below a UITableView in a view controller.
Here s my drawrect for the background. I call setNeedsDisplay when ever the tableview on top scrolls.
-(void)drawRect:(CGRect) rect
{
CGRect topRect = CGRectMake(0, _tableViewRect.origin.y, 320, min( max(0, CGImageGetHeight(top) - _tableViewRect.origin.y), _tableViewRect.size.height));
CGRect segmentRect = CGRectMake(0, topRect.size.height, 320, _tableViewRect.size.height - topRect.size.height);
if(topRect.size.height > 0)
{
CGImageRef newImageRef = CGImageCreateWithImageInRect(top, topRect);
UIImage *newImage = [UIImage imageWithCGImage:newImageRef];
[newImage drawAtPoint:CGPointMake(0,0)];
}
[[UIImage imageWithCGImage: segment] drawAsPatternInRect:segmentRect];
}
It works but it is very chuggy on my 3G. Does anyone have any optimization tips, or another way of doing this?
Cheers