如何删除已在 UILabel 中设置的 UIAppearance 设置?
或者如何更新已经设置好的 UIAppearance?
我创建了一个自定义的 UILabel 方法,如下所示。
标题
- (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
关于ios - 如何从 UILabel 中删除 UIAppearance 设置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45093943/