Swift 中的外观代理/UI_APPEARANCE_SELECTOR? [英] Appearance proxies / UI_APPEARANCE_SELECTOR in Swift?
本文介绍了Swift 中的外观代理/UI_APPEARANCE_SELECTOR?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Apple 文档指出:
The Apple documentation states:
要参与外观代理API,请标记您的外观带有 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
注释属性:
In Objective-C one can annotate properties with UI_APPEARANCE_SELECTOR
like this:
@property (nonatomic, strong) UIColor *foregroundColor UI_APPEARANCE_SELECTOR;
如何在 Swift 中执行相同的操作?
推荐答案
将您的自定义视图属性标记为 dynamic
.
Mark your custom view property as dynamic
.
例如:
class YourCustomView: UIView {
@objc dynamic var subviewColor: UIColor? {
get { return self.yourSubview.backgroundColor }
set { self.yourSubview.backgroundColor = newValue }
}
...
}
那么:
YourCustomView.appearance().subviewColor = UIColor.greenColor()
这篇关于Swift 中的外观代理/UI_APPEARANCE_SELECTOR?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文