Пользовательский UITableviewcell, CGGradient по-прежнему показывает, когда ячейка выбрана? - PullRequest
0 голосов
/ 22 мая 2010

Я использую настраиваемую ячейку таблицы (как быстрая прокрутка 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....

    }

Должен ли я что-то делать в выбранном ячейке кода?

1 Ответ

1 голос
/ 23 мая 2010

похоже, что я нашел вдохновение после публикации ;-) Я только что обернул материал градиента, если (! Self.selected) {рисовать градиент} надеюсь, что это кому-то поможет, это выглядит намного проще и менее интенсивно, чем использованиеuiimagevew (thx Tom)

...