2012-07-09 62 views
0

高亮藍色從http://replyz.com/c/1244746-does-anyone-know-the-exact-cgcolorref-used-to-create-the-selection-highlight-when-using-uitableviewcellselectionstyleblue#繪製使用的UIImage或代碼

我看到有人用代碼做到了,他說,高亮顏色是由一個UIImage。

我在哪裏可以找到圖像?

(我想強調與UITableViewCellSelectionStyleBlue顏色的UIButton)

+1

做的截圖和採取默認的Xcode儀器(小精靈)或其他一種顏色。 或者看看這個psd,也許你會找到你想要的http://www.teehanlax.com/downloads/ios-5-gui-psd-iphone-4s/ – SAKrisT 2012-07-09 08:16:37

回答

0

我發現鏈接http://replyz.com/c/1244746-does-anyone-know-the-exact-cgcolorref-used-to-create-the-selection-highlight-when-using-uitableviewcellselectionstyleblue#包括一些代碼,可用於創建亮點。我用Code創建一個新的UIImage。

下面是代碼:

+ (UIImage *) imageForSelectedBlue { 
    CGRect rect = CGRectMake(0, 0, 10, 10); 
    UIGraphicsBeginImageContext(rect.size); 
    CGContextRef context = UIGraphicsGetCurrentContext(); 

    size_t num_locations = 2; 
    CGFloat locations[2] = { 0.0, 1.0 }; 
    CGFloat components[8] = { 0.021, 0.548, 0.962, 1.000, 0.008, 0.364, 0.900, 1.000 }; 

    CGColorSpaceRef rgbColorspace = CGColorSpaceCreateDeviceRGB(); 
    CGGradientRef selectionGradient = CGGradientCreateWithColorComponents(rgbColorspace, components, locations, num_locations); 

    CGPoint startPoint = CGPointMake(CGRectGetMidX(rect), CGRectGetMinY(rect)); 
    CGPoint endPoint = CGPointMake(CGRectGetMidX(rect), CGRectGetMaxY(rect)); 

    CGContextDrawLinearGradient(context, selectionGradient, startPoint, endPoint, 0); 

    CGGradientRelease(selectionGradient); 
    CGColorSpaceRelease(rgbColorspace); 

    UIImage *img = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 
    return img; 
} 
0

其實,你可以設置按鈕的背景圖像。它更高效。

[button setBackgroundImage:buttonBackgroundPressed forState:UIControlStateHighlighted];