Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Appearance proxies / UI_APPEARANCE_SELECTOR in Swift?

The Apple documentation states:

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

In Objective-C one can annotate properties with UI_APPEARANCE_SELECTOR like this:

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

How can I do the same in Swift?

like image 889
Klaas Avatar asked Oct 02 '14 22:10

Klaas


1 Answers

Mark your custom view property as dynamic.

For example:

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

Then:

YourCustomView.appearance().subviewColor = UIColor.greenColor() 
like image 98
Yoichi Tagaya Avatar answered Sep 28 '22 01:09

Yoichi Tagaya