我正在使用一种技巧在表格单元格上获得渐变。
在我升级到 iPhone 3.0 SDK 后,我注意到当我选择一个单元格时,渐变突出显示不再起作用。
这是渐变代码:
- (void)drawContentView:(CGRect)rect {
CGContextRef context = UIGraphicsGetCurrentContext();
UIColor *textColor = [UIColor whiteColor];
// Apply gradient fill
CGFloat locations[2] = { 0.0, 0.75 };
CGFloat components[8] = {0.50, 0.50, 0.50, 1.0, // Start color
0.23, 0.23, 0.23, 1.0}; // End color
if (self.selected) {
components[0] -= 0.10;
components[1] -= 0.10;
components[2] -= 0.10;
components[4] -= 0.10;
components[5] -= 0.10;
components[6] -= 0.10;
}
CGColorSpaceRef myColorspace = CGColorSpaceCreateDeviceRGB();
CGGradientRef myGradient = CGGradientCreateWithColorComponents (myColorspace, components, locations, 2);
CGPoint start = CGPointMake(0, 0);
CGPoint end = CGPointMake(0, rect.size.height);
CGContextDrawLinearGradient(context, myGradient, start, end, 0);
[textColor set];
CGSize mainTextSize = [self.mainText sizeWithFont:(markedRead ? mainTextReadFont : mainTextFont) constrainedToSize:CGSizeMake(288, 200) lineBreakMode:UILineBreakModeWordWrap];
[self.mainText drawInRect:CGRectMake(6, 4, mainTextSize.width, mainTextSize.height) withFont:(markedRead ? mainTextReadFont : mainTextFont)];
[[UIColor lightGrayColor] set];
[self.subText drawAtPoint:CGPointMake(6, mainTextSize.height + 2) forWidth:288 withFont:subTextFont lineBreakMode:UILineBreakModeTailTruncation];
}
如果不明显,代码if (self.selected) {
决定高亮颜色。
有谁知道这可能是什么原因,可能的解决方案?