Wrong Color in Interface Builder

Wrong color in Interface Builder's color picker

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.

  • When you choose "Save for Web & Devices" from Photoshop, uncheck the "Convert to sRGB" box.

Sample Image

  • 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 VALUE as 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).

Sample Image

More info here, including how to match screenshots.

Weird colors in XCode Interface Builder?

Interface Builder filters colors through your monitor's current color space by default. You can change this in Xcode4 IB by bringing up a Colors dialog, clicking the Sliders tab, then clicking the little dropdown button under the magnifying glass that looks like a color spectrum. This will bring up a list of available color spaces -- select Generic RGB and adjust the sliders as necessary to get the correct color.

See this question for more information, especially the comments on the accepted answer.

iOS: Colors defined in Interface Builder different from colors in Web View

I finally solved my issue: The reason was not UIWebView-specific as I had originally assumed, but caused by the fact, that the colors assigned through Interface Builder were in sRGB color space. Changing to "Generic RGB" and then re-assigning the hex color values solved my issue.

color picker color space

Very helpful was this question and answer (I feel the duplicate flag is unjustified).

Why is color defined in IB different than one defined in code?

This whole issue is fixed by Apple in El Capitan. So if you are using xcode 7 on El Capitan this is no longer an issue. Entering #hex color value doesn't change color space anymore.

Color in storyboard not matching UIColor

Xcode 8+, iOS 10+

I recently faced this problem and none of the posted answers did it. It turns out that with the release of iOS 10 SDK, the UIColor initializer init(red:green:blue:alpha:) now uses the extended sRGB range, so you have to set accordingly when configuring your color values on the Storyboard.

Sample Image

See Apple's documentation: https://developer.apple.com/reference/uikit/uicolor/1621925-init

How to define colors in XCodes' Interface Builder?

To set RGB value in IB you should

  1. Click on corresponding element in Inspector window to invoke "Colors" dialog (e.g. Background color, text color etc)
  2. On the toolbar choose the "Sliders" icon
  3. Choose "RGB Sliders" in combo box.

Now you should be able to set RGB values for the color.

Sorry, I don't know if it is possible to copy color values between different elements easily...



Related Topics



Leave a reply



Submit