如何从 UILabel 中删除 UIAppearance 设置?

How do I remove UIAppearance settings from UILabel?

如何删除已在 UILabel 中设置的 UIAppearance 设置?
或者如何更新已经设置好的 UIAppearance?

我创建了一个自定义的 UILabel 方法,如下所示。

Header

- (void)setAppearanceFont:(UIFont *)font UI_APPEARANCE_SELECTOR;

实施

- (void)setAppearanceFont:(UIFont *)font
{
    _invokeCount += 1;

    NSLog(@"invokeCount: %ld", _invokeCount);
    self.font = font;
}

如果我设置了两次外观,setAppearanceFont 方法被调用了两次。

// set appearance
[[MyAppearanceLabel appearance] setAppearanceFont:font];
....
....
// set appearance from another timing
[[MyAppearanceLabel appearance] setAppearanceFont:font];

// show label
MyAppearanceLabel label* = [[MyAppearanceLabel alloc] 
                               initWithFrame:CGRectMake(0, 0, 100, 100)];
[self.view addSubview:label]; // <= invoked twice here!!

我想确保只调用一次 setAppearance 方法。

在 swift 4 中,我按照以下步骤操作(只需将其设置为 nil):

UILabel.appearance(whenContainedInInstancesOf: [UITableViewCell.self]).textColor = nil