开发者

Custom UITableviewcell, CGGradient still shows when cell is selected?

I'm using a custom tableview cell (like Tweetie's fast scrolling) i've added a gradient to the context, which looks really nice, but when I select the cell, the gradient is still visible. I'm not sure how to go about removing the gradient when the cell is selected? any ideas?

cheers

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 = CG开发者_如何学编程GradientCreateWithColorComponents (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....

    }

Should I be doing something in the if cell selected code?


looks like I've found inspiration after posting ;-) I just wrapped the gradient stuff in if(!self.selected) { draw gradient } hope this helps someone, this appears to be much simpler and less cpu intensive that using a uiimagevew (thx Tom)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜