Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create Named colors in Interface Builder?

How do I setup & use custom named colors in Interface Builder?

Named colors in IB

like image 477
danieltmbr Avatar asked Jun 19 '17 08:06

danieltmbr


People also ask

How do I add custom colors to Xcode?

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.


1 Answers

In Xcode9 you can add "New Color Set" to .xcassets files, where you can set rgba values or use IB's color picker.

Add new Color set to Assets.xcassets in Xcode 9

Then you can use that newly defined color from Interface Builder's color picker, it appears under the Named Colors section.

yourCustomColor appears in IB's color picker, under Named colors section

Or you can use it from code like UIColor(named:"customColorName").

As for now, Xcode9 beta 1 does not support using string literal color names as UIColor (like it works with UIImages), but I hope it will work in a later release.


Unfortunatelly it's only available for iOS11 and later. enter image description here

like image 186
danieltmbr Avatar answered Sep 20 '22 05:09

danieltmbr