xcode Interface Builder 的颜色选择器中的颜色错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12686141/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Wrong color in Interface Builder's color picker
提问by Nicu Surdu
I have an UIImageView with a brown image that will not always reach the top part. The UIImage view is inside a white UIView.
我有一个带有棕色图像的 UIImageView,它不会总是到达顶部。UIImage 视图位于白色 UIView 内。
So, because the top part of the image is a linear brown color, I said I will make the UIView underneath it the same brown color, and the user will not see where the image ends. So far, so good.
所以,因为图像的顶部是线性的棕色,我说我会让它下面的 UIView 变成同样的棕色,用户将看不到图像结束的地方。到现在为止还挺好。
My problem is, when I pick the color in the top part of the image, the color picker picks a more darker color than actually is there :(
我的问题是,当我选择图像顶部的颜色时,颜色选择器会选择比实际颜色更深的颜色:(
Before I click the color picker:

在单击颜色选择器之前:

After I click the color picker:

单击颜色选择器后:

How comes ?
怎么会 ?
回答by Zack Morris
Just wanted to elaborate upon the accepted answer with some screenshots.
只是想通过一些屏幕截图详细说明已接受的答案。
If you want to match RGB values between Photoshop and Xcode exactly(without conversion between colorspaces) then you need to save your images in generic RGB and enter any dropper values using the generic RGB colorspace.
如果您想在 Photoshop 和 Xcode 之间精确匹配 RGB 值(无需在颜色空间之间进行转换),那么您需要将图像保存为通用 RGB 并使用通用 RGB 颜色空间输入任何滴管值。
- When you choose "Save for Web & Devices" from Photoshop, uncheck the "Convert to sRGB" box.
- 当您从 Photoshop 中选择“保存为 Web 和设备”时,请取消选中“转换为 sRGB”框。


- In Xcode, click the colorspace popup in the color picker and choose "Generic RGB", then enter the red, green and blue values from Photoshop, NOT THE HEX VALUEas this reverts back to the sRGB colorspace for some reason (be careful not to tab to the hex field either, as that also changes the colorspace to sRGB).
- 在 Xcode 中,单击颜色选择器中的颜色空间弹出窗口并选择“通用 RGB”,然后从 Photoshop 中输入红色、绿色和蓝色值,而不是十六进制值,因为由于某种原因,这会恢复为 sRGB 颜色空间(注意不要选项卡到十六进制字段,因为这也会将色彩空间更改为 sRGB)。


More info here, including how to match screenshots.
更多信息在这里,包括如何搭配截图。
回答by Nicu Surdu
I've managed to find out a solution/explanation (tho I'm still confused) in this answer: https://stackoverflow.com/a/9203647/460750
我设法在这个答案中找到了一个解决方案/解释(虽然我仍然很困惑):https: //stackoverflow.com/a/9203647/460750
Basically, what I did to solve my issues, was to choose from the RGB "types" select (that little square under the color picker) the Apple RGBoption, and enter the R, G and B values manually, instead of using the picker.
基本上,我为解决我的问题所做的是从 RGB“类型”选择(颜色选择器下的那个小方块)Apple RGB选项中进行选择,然后手动输入 R、G 和 B 值,而不是使用选择器。
Odd...
奇怪的...
回答by Krishna Kishore
Its because the component numbers don't spec a color. We also need to know the color space which xCode uses. Colorspace which encodes or decodes is available in the drop down left to the RGB slider.
这是因为组件编号没有指定颜色。我们还需要知道 xCode 使用的颜色空间。RGB 滑块左侧的下拉菜单中提供了编码或解码的色彩空间。


By default xCode chooses the "Generic RGB" and that is what UIColor uses spec color from RGB. If we use magnifying glass, it will change to "Device RGB” space and that is based on your current screen. So “sRGB" or "Adobe RGB" would be the better or close to what you want if you are using the magnifying glass to pick a color.
默认情况下,xCode 选择“通用 RGB”,这就是 UIColor 使用来自 RGB 的规范颜色。如果我们使用放大镜,它将根据您当前的屏幕更改为“设备RGB”空间。因此,如果您使用放大镜,“sRGB”或“Adobe RGB”会更好或更接近您想要的选择一种颜色。
回答by saranpol
I think Generic RGB also works. the trick is you need to enter number of R G B manually after change the RGB mode in dropdown list
我认为通用 RGB 也有效。诀窍是在下拉列表中更改 RGB 模式后,您需要手动输入 RGB 的数量
Odd... (too)
奇怪……(也)
回答by Alessandro Orrù
UPDATE 10.10.4
更新 10.10.4
I had this issue as well, I reported it to Apple, and it seems to have been solved on 10.10.4 (it was related to the color picker itself, not to Xcode/IB)
我也有这个问题,我向Apple报告了它,它似乎已经在10.10.4上解决了(它与颜色选择器本身有关,而不是与Xcode/IB有关)
Can someone else confirm it?
其他人可以确认吗?
回答by Shai Mishali
This is an old question, but it was important for me to add some info. The onlymethod that has been working for me accurately over the years was to not use PS's Color Picker, but use macOS' built-in "Digital Color Meter".
这是一个老问题,但对我来说添加一些信息很重要。多年来一直对我有效的唯一方法是不使用 PS 的颜色选择器,而是使用 macOS 的内置“数字色度计”。
It's bundled with every installation of macOS and the RGB values emitted from there with "Generic RGB" always reproduce the correct color in Xcode Storyboards.
它与 macOS 的每个安装捆绑在一起,从那里发出的带有“通用 RGB”的 RGB 值总是在 Xcode Storyboards 中重现正确的颜色。

