UIColor与IB颜色(颜色配置文件问题) [英] UIColor vs IB color (color profile issue)

查看:185
本文介绍了UIColor与IB颜色(颜色配置文件问题)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用XCode 8.2.1。
我刚刚了解了颜色配置文件,并且RGB值不是通用的。
但仍然无法理解如何在代码中使其正确。
在Interface Builder中,我为标签选择了预定义的深灰色。通用RGB配置文件中为(85,85,85)。同样在代码中我将另一种标签颜色设置为[UIColor darkGrayColor]。我希望它们具有相同的颜色,但它们是不同的。

I'm using XCode 8.2.1. I just learned about color profiles and that RGB values are not universal. But still can't understand how to make it right in code. In Interface Builder I selected predefined "Dark Gray Color" for a label. It is (85, 85, 85) in Generic RGB profile. Also in code I set another label color to [UIColor darkGrayColor]. I expected them to have the same color, but they are different.

我使用的方法

- (BOOL)getRed:(nullable CGFloat *)red green:(nullable CGFloat *)green blue:(nullable CGFloat *)blue alpha:(nullable CGFloat *)alpha

获取RGB值。对于在IB中设置颜色的标签,我看到实际上(104,104,104)的值对应于当切换到设备RGB配置文件时IB中的值。
所以似乎在代码中使用设备RGB配置文件。

to get RGB values. For the label which color was set in IB I see that values are actually (104,104,104) which correspond to values in IB when I switch to Device RGB profile. So it seems that in code Device RGB profile is used.

所以我的问题是:


  1. 为什么标准的深灰色在IB和代码中设置时会有所不同?

  2. 如何在代码中使用Generic RGB配置文件,这样我就能匹配颜色使用Interface Builder的值?


推荐答案

Hello Jesse请看下面的答案:

Hello Jesse please see answer below:


  • 为什么标准的深灰色在IB和代码中设置时会有所不同?

标准深灰色与<$ c不同$ c> Storyboard 并且以编程方式,因为 Storyboard 使用 sRGB IEC61966-2.1 通用RGB 颜色配置文件默认情况下,当您以编程方式设置它时需要设备RGB 颜色配置文件因为设备RGB iOS设备 iPhone,iPad 具有不同的特性s的显示颜色配置文件。

Standard Dark Gray Color is different using Storyboard and programmatically because Storyboard uses sRGB IEC61966-2.1 or Generic RGB Color Profile by default and when you set it programmatically so it takes Device RGB Color profile because Device RGB iOS devices out there iPhones, iPads have different characteristics in terms of their display color profiles .


  • 如何在代码中使用Generic RGB配置文件,所以我可以使用Interface Builder匹配颜色值吗?

设置<$ c $时c> UIColor 以编程方式,因此您无法选择任何颜色配置文件,因为它将采用设备RGB 颜色配置文件

When you set UIColor programmatically so you have no choice to select any Color Profile because it will take Device RGB Color Profile.

如果你想使它相同,那么在你的故事板中选择你的颜色选择器,打开设置并将其更改为设备RGB

If you want to make it same, So in your storyboard select your Colour picker, Open settings and change it to Device RGB

请参阅以下使用故事板进行颜色配置文件设置的屏幕截图

我希望它会帮助你....

I hope it will help you....

这篇关于UIColor与IB颜色(颜色配置文件问题)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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