Interface Builder的全局调色板

ach*_*chi 11 interface-builder uicolor ios swift ibinspectable

在swift中,我正在编写一个扩展(如Obj-C类),它在代码类方法中维护"房屋颜色".我想知道是否有一种方法可以使用IBInspectable或其他东西使接口构建器可以访问此颜色扩展,而不是将颜色专门附加到UIView子类,就像我在很多IBInspector样本用法中看到的那样.

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() }
}
Run Code Online (Sandbox Code Playgroud)

ach*_*chi 2

我发现这个问题的最佳解决方案是构建一个房屋颜色的资产目录,可供 Interface Builder 使用。

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