danieltmbr
danieltmbr

Reputation: 1042

How to create Named colors in Interface Builder?

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

Named colors in IB

Upvotes: 13

Views: 2892

Answers (1)

danieltmbr
danieltmbr

Reputation: 1042

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

Upvotes: 18

Related Questions