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?
To create a color from our palette, we can do it directly by selecting the Assets. xcassets folder (or creating our own . xcassets folder for colors) in the project navigator (Project Navigator). Then we right click and select New Color Set.
You need to create a new color by right-clicking anywhere in the list to open a menu, just click Color Set and you name the color however you want. Now open the Inspectors tab in the upper-right of your screen, you will see options that allow you to modify that color set.
Since Xcode 9.0 we've been able to create named colors directly inside asset catalogs, which means it's possible to select a precise color once then use it uniformly across all code and storyboards. To try this out, open your asset catalog, click the + button, then choose New Color Set from the menu that appears.
Open your asset catalog, click the + and add a color set. Click on the color that was created and you can name it and set the color using the inspector. Thereafter that color shows up in storyboard color chooses in the area called Named Colors.
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.
To set RGB value in IB you should
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...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With