Menu

Asset Colors in Packages - Forest and the Trees
📰
0

Asset Colors in Packages - Forest and the Trees

Forest and the Trees·Doug Marttila·about 1 month ago
#a9jmfq5r
#comment#package#swift#xcode#respond#color
Reading 0:00
15s threshold

Xcode allows you to easily add custom colors to the Assets file in your project. Add a Color Set, then use the Inspector to modify the color. To use your new color in your project, adding a color extension with the custom color’s name makes your life easier. Example below… extension Color { static let myAwesomeClr = Color("theNameOfMyColorInAssets") } Then you can do things like… Color(.myAwesomeClr) If you want to include that color in a Package, you need to.. Declare your extension public (like everything in a Package) Create a UIColor and cast that as a Color. (This took me a while to figure out which is why I am posting this.) See below… public extension Color { static let myAwesomeClr = Color(UIColor(named: "theNameOfMyColorInAssets", in: .module, compatibleWith: nil)!) } And, you need to add a resource target to your Package file… let package = Package( name: "YourPackageName", ... some common package info here omitted for this example ....…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More