ios - 如何从 UILabel 中删除 UIAppearance 设置?

标签 ios objective-c uiappearance

如何删除已在 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/

相关文章:

ios - 最快的方法 - 字符串组件之间的逗号

objective-c - 对受 OAuth 保护的 URL 进行 GET 调用

ios - 层次结构中的 UIAppearance 实例

ios - 蓝牙iOS配对

iphone - 如何在不覆盖文件内容的情况下写入文本文件?

iphone - 支持 UIKit UIAppearance 协议(protocol)的类的最终列表

rstudio 颜色外观,包名称的特定颜色,front::

iphone - 参数和选择器

ios - 尝试安装 Pod 但出现错误

iphone - 键盘在 UIScrollView 中隐藏文本字段。如何根据键盘移动文本字段?