I want to be able to define a custom color in a single place and then have access to it both programmatically and in Interface Builder. For coding I could create a UIColor extension. For visual designing in IB I could create a custom color palette. What is the best technique that will simultaneously work with both?
Unfortunately you can't do this.
You can define a colour that you can access in code through an extension of UIColor. Or you can add a colour to the pallets in Interfact Builder.
But you can't have both.
Hmm...
What you could do is something similar to what PaintCode does.
Create an object in code that has a IBOutletCollection and then when the view loads it will iterate the outlets and set the background colour etc... to your fancy colour.
Xcode 9 allows you to place colors in the Asset catalog. This is Apple's answer to those who want to have their colors synced across both.
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