Skip to content
This repository has been archived by the owner on Sep 17, 2022. It is now read-only.
/ Mixer Public archive

A tiny library helping to centralize & manage color definitions together with design

License

Notifications You must be signed in to change notification settings

ios-studio/Mixer

Repository files navigation

Mixer Build Status codecov.io Carthage compatible

Centralize your color definitions in a CSV file & easily share them for people to edit.

Installation

Add the following your Cartfile:

For Swift 3:

github "ios-studio/Mixer" ~> 1.0.0

For Swift 2.x:

github "ios-studio/Mixer" ~> 0.1.2

Add the following your Podfile:

For Swift 3:

pod "Mixer", "~> 1.0.0"

For Swift 2.x:

pod "Mixer", "~> 0.1.2"

Default Setup

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.

Configuring

Mixer can be passed a MixerConfiguration object where you can specify another path to your colors file.

Using Mixer

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:

Using your color definition

Remember the definition of Color from above? This is how to get a color according to your definitions:

let color = mixer.colorFor(Color.Blue)

Using a string

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

Contributions

Yes please!