Swift中的外观代理/ UI_APPEARANCE_SELECTOR?

前端之家收集整理的这篇文章主要介绍了Swift中的外观代理/ UI_APPEARANCE_SELECTOR?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
苹果文档说明:

To participate in the appearance proxy API,tag your appearance
property selectors in your header with UI_APPEARANCE_SELECTOR.

在Objective-C中,可以使用UI_APPEARANCE_SELECTOR注释属性,如下所示:

@property (nonatomic,strong) UIColor *foregroundColor UI_APPEARANCE_SELECTOR;

我怎么能在Swift中做同样的事情?

自定义视图属性标记为动态。

例如:

class YourCustomView: UIView {
    dynamic var subviewColor: UIColor? {
        get { return self.yourSubview.backgroundColor }
        set { self.yourSubview.backgroundColor = newValue }
    }
    ...
}

然后:

YourCustomView.appearance().subviewColor = UIColor.greenColor()
原文链接:https://www.f2er.com/swift/321045.html

猜你在找的Swift相关文章