iosswiftinterface-builderuicoloribinspectable

Global Color Palette for Interface Builder


In swift i'm writing an extension (like Obj-C category) that maintains in code class methods of "house colors." I'm wondering if there is a way to make this color extension accessible to Interface builder using IBInspectable or something else as opposed to attaching colors specifically to UIView subclasses as i've seen in a lot of IBInspector sample usage.

extension UIColor {
    // house blue
    @IBInspectable var houseBlue: UIColor { return UIColor(red:(51/255), green:(205/255), blue:(255/255), alpha:(1)) }

    // house gray
    @IBInspectable var houseGray: UIColor { return UIColor(white:0.4, alpha: 1) }

    // house white
    @IBInspectable var houseWhite: UIColor { return UIColor.whiteColor() }
}

Solution

  • The best solution I have found to this problem is to build an asset catalog of house colors, which can be used by Interface Builder.

    https://help.apple.com/xcode/mac/current/#/dev10510b1f7