Centralize your color definitions in a CSV file & easily share them for people to edit.
Via Carthage:
Add the following your Cartfile:
For Swift 3:
github "ios-studio/Mixer" ~> 1.0.0For Swift 2.x:
github "ios-studio/Mixer" ~> 0.1.2Via CocoaPods:
Add the following your Podfile:
For Swift 3:
pod "Mixer", "~> 1.0.0"For Swift 2.x:
pod "Mixer", "~> 0.1.2"Mixer will look for a file named Colors.csv in the specified bundle or at the specified path. The contents of the file should look like this. It is important to keep the headers as shown, otherwise Mixer will not be able to read the file.
For the colors you'd like to use in your project, define a class which conforms to the protocol MixerColor. The only requirement of that protocol is that the object responds to the property name, so for example it could look like:
enum Color: String, MixerColor {
case Blue = "Blue"
case Red = "Red"
var name: String { return rawValue }
}Where "Blue" corresponds to the name of a color in the csv file.
Mixer can be passed a MixerConfiguration object where you can specify another path to your colors file.
Pass the bundle to initialize. Mixer will look up the Colors file in the bundle and cache it for subsequent initializations in the same process:
let bundle = Bundle(forClass: self.dynamicType)
let mixer = Mixer(bundle: bundle)Typically, all you will then use is the colorFor method, which you can use in two ways:
Remember the definition of Color from above? This is how to get a color according to your definitions:
let color = mixer.colorFor(Color.Blue)This is a convenience method to be able to use Mixer with @IBDesignable / @IBInspectable. Since @IBInspectable does not yet work with enum types, you can use the version of colorFor without a type check like so:
let color = mixer.colorFor("Blue")For an example involving @IBDesignable, go to the wiki
Yes please!