如何访问UIColor的颜色组件? [英] How to access the color components of an UIColor?

查看:45
本文介绍了如何访问UIColor的颜色组件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

即我想知道蓝色的价值.我如何从UIColor中得到它?

i.e. I want to know the value of blue. How would I get that from an UIColor?

推荐答案

UIColor类不提供有关颜色成分的信息.您必须改为从其CGColor获取组件.请注意,组件的数量取决于CGColorRef中使用的颜色空间.

UIColor class does not provide information about color components. You must get components from its CGColor instead. Note that the number of components depends on color space used in CGColorRef.

此代码显示蓝色的组件:

This code prints components for blue color:

UIColor* color = [UIColor blueColor];
int n = CGColorGetNumberOfComponents(color.CGColor);
const CGFloat *coms = CGColorGetComponents(color.CGColor);
for (int i = 0; i < n; ++i)
    NSLog(@"%f", coms[i]);

这篇关于如何访问UIColor的颜色组件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆