How do I setup & use custom named colors 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.
In Xcode9 you can add "New Color Set" to .xcassets files, where you can set rgba values or use IB's color picker.
Then you can use that newly defined color from Interface Builder's color picker, it appears under the 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.
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