2010-05-22 50 views
0

我正在使用自定义tableview单元格(就像Tweetie的快速滚动) 我已经添加了上下文渐变,看起来非常好,但是当我选择单元格时,渐变仍然可见。我不知道如何去选择单元格时删除渐变?有任何想法吗?自定义UITableviewcell,CGGradient仍然显示何时选中单元格?

欢呼

- (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.... 

    } 

我应该做的,如果选择的单元代码的东西吗?

+0

看起来像我找到灵感后发布;-) 我刚刚结束的梯度东西在 \t如果(!self.selected) { 平局梯度 } 希望这有助于某人,这似乎是更简单,更少CPU密集使用uiimagevew – 2010-05-22 11:18:49

回答

1

看起来像是在发布后我发现了灵感;-)我只是将渐变的东西包裹在if(!self.selected){绘制渐变}中,希望这可以帮助某人,这看起来更简单和更少的CPU密集使用uiimagevew (感谢汤姆)

相关问题