12

I would like to copy colors between elements in the Interface Builder or define them using RGB values. For example, I'd like to copy the background color of a button to another button without duplicating the button.

Alternatively, entering exact RGB codes in Interface Builder would suffice; that way I can make sure my buttons have the exact same color.

Currently I only know how to do this programmatically, but surely there is a way to do it in Interface Builder?

Mark Amery
  • 143,130
  • 81
  • 406
  • 459
favo
  • 5,426
  • 9
  • 42
  • 61

4 Answers4

15

To copy a custom-defined color between different elements you should save it. To do this, first define the color in the Colors window (e.g. by entering RGB values into field as described in Vladimir's answer). Then simply drag from the top panel of the colors window where your resulting color is shown into one of the small square boxes at the bottom. It will be saved.

Illustration

Mark Amery
  • 143,130
  • 81
  • 406
  • 459
M.Y.
  • 1,105
  • 1
  • 11
  • 30
  • 1
    Exactly what I was looking for. It so small I've missed it for years. – Nikola Lajic Feb 13 '13 at 09:31
  • 4
    can I name this color? In code I create a category on UIColor so that I can use our designer's style guide. He uses a few types of gray that may otherwise be hard to distinguish. Would be great if I could somehow name that saved color. – horseshoe7 Sep 22 '14 at 07:31
  • To give names to these colors, and the palettes, use this [answer](http://stackoverflow.com/questions/28501010/add-a-custom-color-palette-to-xcode-interface-builder) – Diego Freniche May 06 '15 at 15:42
11

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...

Vladimir
  • 170,431
  • 36
  • 387
  • 313
8

I know it is late answer but it is possible create custom profile in Interface Builder.

First you need to Click on Color of any component in Utilities panel.

Click on any Color

Then select 3rd tab from the top panel and Click on Settings icon on the right.

Select third tab and click settings button

Then select the New option

Select New option

After creating you can then rename the profile

Rename the color profile

Then click on the color picker and select a color from your color pallet

Click on color picker

Lastly drag the picked image to upper window to save that color. You can also change the name of picked color.

Drag the image to the upper window

And by repeating this you can add all your color needed for your project in this color pallet. Next you need to change color of component such as Button, Label you just need to select this color profile and select color. Hope it is helpful.

kazi.munshimun
  • 2,168
  • 19
  • 17
5

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.

enter image description here

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

enter image description here

More info here, including how to match screenshots.

Community
  • 1
  • 1
Zack Morris
  • 4,727
  • 2
  • 55
  • 83