我正在使用一种技巧来获得表格单元格的渐变。
升级到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) {
中的代码会决定高光颜色。
任何人都知道可能导致这种情况的原因,可能是解决方案吗?
答案 0 :(得分:4)
实际上我自己解决了这个问题。
if (self.selected) {
已改为
if (self.highlighted) {
在iPhone 3.0中