如何在ios中获取自定义颜色的RGB分量
我想使用该方法以编程方式设置自定义颜色[UIColor colorWithRed:(CGFloat)红绿:(CGFloat)绿蓝:(CGFloat)蓝alpha:(CGFloat)alpha];
为此我需要知道 RBG 组件的值。
我想知道有什么方法可以获取自定义颜色的 RBG 组件,以便我可以在上述方法中使用它们。
I would like to set custom color programmatically using the method[UIColor colorWithRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha];
For which i need to know the value of RBG components.
I would like to know is there any way by which i can get the RBG components of a custom color so that i can use them in the above mentioned method.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以使用每个 Mac OS X 安装中附带的 DigitalColor Meter.app。您可以在
~/Applications/Utilities/DigitalColor Meter.app
中找到它。用它来检查鼠标悬停的任何像素的 RGB 值。获得这些值后,只需将它们除以255.0
,因为+colorWithRed:green:blue:alpha:
需要 0 到 1 之间的浮点值。You can use the DigitalColor Meter.app included with every Mac OS X install. You can find it in
~/Applications/Utilities/DigitalColor Meter.app
. Use it to inspect the RGB values of any pixel you mouse over. Once you have the values, you just need to divide them by255.0
because+colorWithRed:green:blue:alpha:
is expecting a floating point value between 0 and 1.您可以使用 Xcode 本身获取自定义颜色的 RGB 值:
单击“颜色”框的箭头,然后在出现的对话框中选择其他颜色。
然后您可以使用 RGB 滑块选项来获取 RGB 值
You can use Xcode itself to get RGB value of custom color:
Click the arrow for the Color box and in the resulting dialog box choose others.
And then you can use RGB Slider option to get RGB values
为了精确匹配颜色,“应用程序/实用程序/”中有一个名为“DigitalColor Meter”的实用程序,可以获取屏幕上任何内容的 RGB。截取您想要复制的颜色的屏幕截图,然后使用此工具获取信息。
To match a color exactly, there is a great utility called "DigitalColor Meter" located in Applications/Utilities/ that can get the RGB for anything on your screen. Take a screen shot of the color you want to replicate, then use this tool to get the information.
实际上不需要使用DigitalColor Meter,我们可以使用小搜索图标 在界面生成器中的颜色选择器上,我们可以使用它精确调整我们喜欢的颜色。也可以使用其中可用的 RBG 比例查找颜色值。
Actually there is no need for using DigitalColor Meter instead we can use the small Search Icon on color picker in the Interface Builder with which we can exactly adjust the color that we like.It is also possible to look up the color values using RBG scales available in it.