如何将UIExtendedSRGBColorSpace匹配到我的颜色值 [英] How to match UIExtendedSRGBColorSpace to my color values

查看:926
本文介绍了如何将UIExtendedSRGBColorSpace匹配到我的颜色值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用XCode可视编辑器设置UIButton的颜色.我使用RGB滑块进行设置.

I set the color for UIButton with the XCode visual editor. I set it using RGB sliders.

然后我设置变量green:

let green = UIColor(red: 0, green: 210/255, blue: 0, alpha: 1)

当我打印出green值和UIButton.backgroundColor时,我相应地得到了​​下一个值:

When I printed out green value and UIButton.backgroundColor I got next values accordingly:

UIExtendedSRGBColorSpace -0.146119 0.836984 -0.0130851 1
UIExtendedSRGBColorSpace 0 0.823529 0 1

因此,据我所知,颜色空间相等,但值不相等.为什么会这样呢?苹果的UIButton()会进行一些隐藏的转换吗?目的是什么?此按钮属性和green属性是否可以具有相同的值.

So, as I guess, the color spaces are equal, but values are not. Why is it so? The Apple's UIButton() does some hidden conversion? What is the purpose? Is it possible to have the same values for this button property and for green property.

推荐答案

"RGB滑块"弹出菜单旁边有一个按钮, 允许您选择颜色空间:

Next to the "RGB Sliders" popup menu there is a button which allows you to choose a color space:

在您的情况下,将其设置为显示P3",即 比sRGB颜色空间更大",并允许显示更多 带有P3显示屏的新型设备上的颜色这种颜色代表 在扩展的sRGB色彩空间"中,其中的分量不是 限制为0.0到1.0(请参见 UIColor 中的颜色和色彩空间" 欲获得更多信息).就您而言

In your case it is set to "Display P3", a color space which is "larger" than the sRGB color space and allows to display more colors on newer devices with a P3 display. This color is represented in the "extended sRGB colorspace" where the components are not restricted to the range from 0.0 to 1.0 (see "Color and Color Spaces" in UIColor for more information). In your case

UIExtendedSRGBColorSpace -0.416964 0.838774 -0.249501 1

具有负的红色和蓝色成分,即色域外的颜色 sRGB.

with negative red and blue components, i.e. a color outside color gamut of sRGB.

如果将颜色选择器中的颜色空间设置为"sRGB",则0/210/0的结果将为

If you set the colorspace in the color chooser to "sRGB" then the result for 0/210/0 will be

UIExtendedSRGBColorSpace 0 0.823529 0 1

且与

let green = UIColor(red: 0, green: 210/255, blue: 0, alpha: 1)

或者,以编程方式使用Display P3颜色空间 也可以创建颜色:

Alternatively, use the Display P3 color space for the programmatically created color as well:

print(label.backgroundColor!)
// UIExtendedSRGBColorSpace -0.416964 0.838774 -0.249501 1

let green = UIColor(displayP3Red: 0, green: 210/255, blue: 0, alpha: 1)
print(green)
// UIDisplayP3ColorSpace 0 0.823529 0 1
print(UIColor(cgColor: green.cgColor))
// UIExtendedSRGBColorSpace -0.416964 0.838774 -0.249501 1

print(label.backgroundColor! == green)
// true

这篇关于如何将UIExtendedSRGBColorSpace匹配到我的颜色值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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