简体   繁体   English

Xcode 6 Interface Builder-颜色选择器是否奇怪/错误?

[英]Xcode 6 Interface Builder - color picker oddity/bug?

I've recently been tearing my hair out over trying to set the same background color for views styled using Interface Builder, and views styled programatically using [UIColor colorWithRed: green: blue: alpha:] . 最近,我一直在努力尝试为使用Interface Builder设置样式的视图和使用[UIColor colorWithRed: green: blue: alpha:]以编程方式设置样式的视图设置相同的背景色。 Despite setting the same RGB values, the views styled in IB were a slightly different color shade to those styled in code. 尽管设置了相同的RGB值,但是IB样式中的视图与代码样式中的视图略有不同。

I finally realised it was to do with color spaces - when I examined the views in IB using the color picker, it showed the color space was set to 'sRGB' rather than the default of 'Generic RGB' which UIColor uses. 我最终意识到这与颜色空间有关-当我使用颜色选择器检查IB中的视图时,它显示颜色空间设置为“ sRGB”,而不是UIColor使用的默认“ Generic RGB”。 I never changed the color space setting myself. 我从未改变自己的色彩空间设置。 I then realised what is happening is that when you manually type in the RGB values in the color picker, it changes the color space to 'sRGB' without you knowing therefore giving a different color. 然后,我意识到正在发生的事情是,当您在颜色选择器中手动键入RGB值时,它会将颜色空间更改为“ sRGB”,而您不知道因此会给出不同的颜色。 However if you use the mouse to drag the slider bars to change the values then the color space remains at 'Generic RGB' and all is well. 但是,如果使用鼠标拖动滑块来更改值,则色彩空间将保持在“通用RGB”,并且一切都很好。

Is this a bug, or am I misunderstanding the color picker? 这是一个错误,还是我误会了拾色器? I'm using Xcode 6.1. 我正在使用Xcode 6.1。

A solution is to use "Device RGB" and not "Generic RGB". 解决方案是使用“设备RGB”而不是“通用RGB”。 在此处输入图片说明

I tried your 'technique' with only moving sliders, but in my case even this changes profile back to sRGB. 我仅使用移动的滑块尝试了“技术”,但就我而言,即使将配置文件更改回sRGB。 I think its definitely a bug because the only 'workaround' to get exactly same colours in code and interface builder I found is the following: 我认为这绝对是一个错误,因为在代码和界面生成器中获得完全相同颜色的唯一“解决方法”如下:

  1. Decide on the RGB code you want to use (in Generic RGB) in my case was "#1C202C" 在我的情况下,决定要使用的RGB代码(在通用RGB中)是“#1C202C”

  2. Open new image in Photoshop in Generic RGB profile and fill the background with the color 在通用RGB配置文件中的Photoshop中打开新图像,并用颜色填充背景

  3. Go to menu Edit->Convert to Profile and convert to "sRGB IEC61966-2.1" 转到菜单“编辑”->“转换为配置文件”,然后转换为“ sRGB IEC61966-2.1”

  4. Open Photoshop's color picker and pick on the new color, new rgb code will show up ... in my case "#252b3a" 打开Photoshop的颜色选择器并选择新颜色,新的rgb代码将显示出来……在我的情况下为“#252b3a”

If you use this code in interface builder then colors from code and IB will be exactly the same. 如果在界面生成器中使用此代码,则代码和IB中的颜色将完全相同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM