我的应用程序中有许多 UILabel 元素,我正在寻找一种简单的方法来使用 UIAppearance 代理对象来设置它们的样式。我目前的方法是创建配备 UI_APPEARANCE_SELECTOR 装饰器的 UILabel 的不同子类,以便可以通过 [UILabelSubclass appearance]
调用访问。您可以找到我用作引用的来源 here和 here .
问题是我不想设置字体大小,而只想设置依赖于 Storyboard 中定义的大小的字体系列。
如何在子类中设置它?
最佳答案
这是一个使用 UIAppearance 代理的简单类别:
@interface UILabel (FontName)
- (void)setFontName:(NSString *)name UI_APPEARANCE_SELECTOR;
@end
@implementation UILabel (FontName)
- (void)setFontName:(NSString *)name {
self.font = [UIFont fontWithName:name size:self.font.pointSize];
}
@end
关于ios - 使用 UIAppearance 代理样式化 UILabel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17432432/