How do I setup & use custom named colors in Interface Builder?
Asked
Active
Viewed 2,770 times
1 Answers
18
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.

danieltmbr
- 1,022
- 12
- 20
-
3Wow, thanks! It helped me a lot!! Is it backward compatible with iOS 8,9? – Kádi Jun 19 '17 at 09:06
-
2Unforutnatelly it's not backward compatible. – danieltmbr Jun 19 '17 at 09:15
-
In iOS 10 app crashes with not so obvious error message "Could not instantiate class named _UIColorAttributeTraitStorage". – Miroslav Hrivik Sep 14 '17 at 07:59
-
1Does anyone succeeded in using the same technique in macOS project? – Andriy Sep 16 '17 at 22:18
-
No, not so far, unfortunately :( – danieltmbr Sep 18 '17 at 11:50
-
1TOo bad it is not backward compatible. – tounaobun Sep 23 '17 at 02:12
-
3Yes, it crashed on iOS 10, so I wrote a shell which will batch replace Named colors to RGB when Xcode build. – Lei Oct 23 '17 at 09:21
-
Anyone got any alternate solution because only 52% iPhones users are using iOS 11. – Alok Dec 05 '17 at 04:45
-
@Artwalk could you please explain more – cs4alhaider Jan 26 '19 at 18:55