2010-05-22 4 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

를 사용하여 보이는 (!이 self.selected) { 그리기 그라데이션 } 경우 이 사람이 도움이되기를 바랍니다. 이것은 uiimagevew를 사용하면 훨씬 간단하고 CPU 사용량이 적게 드는 것으로 보입니다. –

답변

1

내가 게시 한 후 영감을 찾은 것처럼 보입니다 .--) 방금 그라디언트를 포장했습니다. (! self.selected) {그라디언트 그릴} 누군가에게 도움이되기를 바랍니다. 훨씬 간단하고 적은 CPU 사용량이 필요합니다. 난 그냥 \t에 그라데이션 물건을 포장 ;-) 내가 게시 한 후 영감을 발견했습니다 같은 uiimagevew (THX 톰)

관련 문제