我正在使用一个自定义的tableview单元格(就像Tweetie的快速滚动)
我在上下文中添加了一个渐变,看起来很不错,但是当我选择单元格时,渐变仍然可见。我不知道如何删除梯度时,细胞被选中?有什么想法吗?
干杯
尼克
- (void)drawContentView:(CGRect)r
{
CGContextRef context = UIGraphicsGetCurrentContext();
UIColor *backgroundColor = [UIColor whiteColor];
UIColor *textColor = [UIColor blackColor];
UIColor *dateColor = [UIColor colorWithRed:77.f/255.f green:103.f/255.f blue:155.f/255.f alpha:1];
if(self.selected)
{
backgroundColor = [UIColor clearColor];
textColor = [UIColor whiteColor];
}
[backgroundColor set];
CGContextFillRect(context, r);
CGGradientRef myGradient;
CGColorSpaceRef myColorspace;
size_t num_locations = 2;
CGFloat locations[2] = {0.0, 1.0};
CGFloat components[8] = {0.9f, 0.9f, 0.9f, 0.7f,
1.0f, 1.0f, 1.0f, 1.0};
myColorspace = CGColorSpaceCreateDeviceRGB();
myGradient = CGGradientCreateWithColorComponents (myColorspace, components,
locations, num_locations);
CGColorSpaceRelease(myColorspace);
CGPoint startPoint, endPoint;
startPoint.x = 0;
startPoint.y = self.frame.size.height;
endPoint.x = 0;
endPoint.y = self.frame.size.height-15;
CGContextDrawLinearGradient (context, myGradient, startPoint, endPoint, 0);
CGGradientRelease(myGradient);
}
我应该在if单元格中选择代码吗?