我正在使用自定义的tableview单元格(如Tweetie的快速滚动) 我在上下文中添加了一个渐变,看起来非常好,但是当我选择单元格时,渐变仍然是可见的。我不确定在选择单元格时如何去除渐变?有任何想法吗?
欢呼声
的Nik
- (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);
//add gradient
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, // Bottom Colour: Red, Green, Blue, Alpha.
1.0f, 1.0f, 1.0f, 1.0}; // Top Colour: Red, Green, Blue, Alpha.
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; // just keep the gradient static size, never mind how big the cell is
CGContextDrawLinearGradient (context, myGradient, startPoint, endPoint, 0);
CGGradientRelease(myGradient);
//gradient end
//rest of custom drawing goes here....
}
我应该在if cell选择的代码中做些什么吗?
答案 0 :(得分:1)
看起来我在发布后找到了灵感;-)我只是将渐变内容包装在if(!self.selected){draw gradient}希望这可以帮助某人,这看起来更简单,并且使用更少cpu一个uiimagevew (汤姆)