Latest 0.0.1
Homepage https://github.com/kuyazee/Palettable
License MIT
Platforms ios 8.0
Authors

Twitter
Github
Cocoapods

Palettable is a simple Swift extension wrapper for creating your own custom color palettes.

Installation

To install Palettable via cocoapods, simply use the add this in your podfile and then run pod install

pod 'Palettable'

To install Palettable manually, simply drag the Palettable.swift in your project files.

How it works

Palettable is just a protocol which can help you make color palettes for your app.

public protocol ColorConvertible {
    var colorValue: UIColor { get }
}

public protocol Palettable {
    associatedtype Palette where Palette: ColorConvertible
}

extension Palettable {
    public static func kz(_ palette: Palette) -> UIColor {
        return palette.colorValue
    }
}

You use this by subclassing UIColor to Palettable for example:

extension UIColor: Palettable {
    enum Palette: ColorConvertible {
        // insert other cases for other colors
        // you can use whatever naming conventions you want
        case primary
        case secondary

        var colorValue: UIColor { 
            switch self {
            case .primary: return .black
            case .secondary: return .white
            }
        }
    }
}

Now to use this within the code is as simple as using the .kz(_:) method for example:

let label: UILabel = UILabel()
label.textColor = .kz(.primary)

let button: UIButton = UIButton()
button.set

Why you should use this?

This protocol can be used with other color libraries such as SwiftHEXColors, Chameleon, Hue, etc.,

An example usage would look like this for SwiftHEXColors

import SwiftHEXColors

extension UIColor: Palettable {
    enum Palette: ColorConvertible {
        case primary
        case secondary

        var colorValue: UIColor { 
            switch self {
            case .primary: return UIColor(hexString: "#FFFFFF")
            case .secondary: return UIColor(hexString: "#000000")
            }
        }
    }
}

Latest podspec

{
    "name": "Palettable",
    "version": "0.0.1",
    "summary": "A helper protocol in for creating color palettes",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Zonily Jame Pesquera": "[email protected]"
    },
    "social_media_url": "https://www.linkedin.com/in/zjgpesquera/",
    "swift_version": "3.2",
    "platforms": {
        "ios": "8.0"
    },
    "source": {
        "git": "https://github.com/kuyazee/Palettable.git",
        "tag": "0.0.1"
    },
    "source_files": [
        "Classes",
        "**/*.{h,swift}"
    ],
    "description": "A helper protocol in for creating color palettes",
    "homepage": "https://github.com/kuyazee/Palettable"
}

Pin It on Pinterest

Share This