UIColor 获取颜色的RGB值

CGFloat R, G, B;
    CGColorRef color = [UIColor clearColor].CGColor;
    // Returns the number of color components (including alpha) associated with a Quartz color
    NSInteger numComponents = CGColorGetNumberOfComponents(color);
    
    if (numComponents == 4)
    {
        const CGFloat *components = CGColorGetComponents(color);
        R = components[0];
        G = components[1];
        B = components[2];
    }
    NSLog(@"r= %f,g=%f,b=%f",R,G,B);

输出为 :r=0.000000,g=0.000000,b=0.000000

猜你喜欢

转载自1021082712.iteye.com/blog/2077353
今日推荐