2009-08-08 48 views
0

我正在使用技巧在我的表格單元格上獲得漸變效果。iPhone 3.0 SDK中的漸變技巧發生了變化?

我升級到iPhone 3.0 SDK後,我注意到當我選擇一個單元格時,漸變突出顯示不再有效。

iPhone 2.2.1
​​

iPhone 3.0
http://i32.tinypic.com/2i6dnyp.jpg


這裏的梯度代碼:

- (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) {代碼決定高光的顏色。


任何人都知道可能會導致這樣,可能的解決方案?

回答

4

其實自己解決了這個問題。

if (self.selected) {
已更改爲
if (self.highlighted) {
在iPhone 3.0

+0

其實,你可以'highlighted'而不'selected'(以及可能的其他方式太)。通常我會檢查是否有或者在我的情況下。 – jbrennan 2009-09-10 23:35:05