UIAppearance,请参阅Interface Builder中的结果?

all*_*ire 14 iphone xcode interface-builder ios swift

我正在使用UIAppearance很多导航控制器和其他UI对象,我想知道是否可以在Interface Builder中设置我的相关对象(可能有一些神奇的伏都教@IBDesignable?)

San*_*man 6

matt对这个问题的评论是正确的.您可以在prepareForInterfaceBuilder方法中成功使用UIAppearance代理.

例:

@IBDesignable
class MyCustomView: UIView {

    override func prepareForInterfaceBuilder() {
        MyCustomView.appearance().backgroundColor = UIColor.redColor()
    }
}
Run Code Online (Sandbox Code Playgroud)

这将导致所有MyCustomView实例在IB中呈现为红色.