2010-05-22 52 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 (感謝湯姆)

相關問題