How do I setup & use custom named colors in Interface Builder?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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.