UITableViewCell外观不会改变textLabel字体

oop*_*psi 6 appearance uitableview uikit ios

我的didFinishLaunchingWithOptions函数中有以下代码:

[[[UITableViewCell appearance] textLabel]setFont:[UIFont fontWithName:@"someFont" size:12]];
Run Code Online (Sandbox Code Playgroud)

但由于某些原因,这不会改变我的表格单元格中的文本.

如果在表中委托函数cellForRowAtIndexPath我添加

cell.textLabel.font = [UIFont fontWithName:@"someFont" size:12];
Run Code Online (Sandbox Code Playgroud)

它确实将字体更改为我想要的字体.

有任何想法吗?

Ash*_*lls 9

使用外观代理不支持设置a的font属性UITableViewCell.

您可以通过查找该类的头文件来确定支持哪些属性UI_APPEARANCE_SELECTOR.

看看,UITableViewCell.h你会发现只separatorInset支持(并且backgroundColor它的超类支持UIView):

@property (nonatomic) UIEdgeInsets separatorInset NS_AVAILABLE_IOS(7_0) UI_APPEARANCE_SELECTOR; // allows customization of the separator frame


UIAppearance协议参考:

要支持外观自定义,类必须符合UIAppearanceContainer协议,并且必须标记相关的访问器方法UI_APPEARANCE_SELECTOR.