绘制UITableViewCell的渐变背景的思路
绘制渐变的背景图片
得到背景图片后设置ContentView的背景颜色
-(UIImage *)backImage{
CGSize size=CGSizeMake(320,44);
UIGraphicsBeginImageContext(size);
CGColorSpaceRefcolorSpace=CGColorSpaceCreateDeviceRGB();
floatcomponents[12]={251/255.0,251/255.0,251/255.0,1.0,235/255.0,235/255.0,235/255.0,1.0,251/255.0,251/255.0,251/255.0,1.0};
floatlocations[3]={0.0,0.5,1.0};
CGGradientRefgradient=CGGradientCreateWithColorComponents(colorSpace, components, locations,3);
CGContextDrawLinearGradient(UIGraphicsGetCurrentContext(),gradient, CGPointMake(0, 0),CGPointMake(0, 44),kCGGradientDrawsAfterEndLocation);
CGColorSpaceRelease(colorSpace);
CGGradientRelease(gradient);
UIImage*image=UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
returnimage;
}