【发布时间】:2014-09-26 00:25:56
【问题描述】:
我在我的应用中使用 UIAppearanceProxy,如下所示:
UILabel *label = [UILabel appearance];
label.font = myAppFont;
label.textColor = myAppTextColor;
不过,有时我想覆盖默认字体以使用来自Awesome Font 的字形。我是这样做的:
NSString *basePos = [NSString stringWithFormat:@"%d %@", (int)self.user.positives, kUpArrow];
NSMutableAttributedString *posString = [[NSMutableAttributedString alloc] initWithString:basePos];
[posString setAttributes:@{NSFontAttributeName:[UIFont fontWithName:@"FontAwesome" size:18]} range:NSMakeRange([posString length] - 1, 1)];
[self.positivesLabel setAttributedText:posString];
当视图构建并显示时,这非常有用,但是如果我导航到另一个页面(我正在使用 UIPageViewController)并返回,我的属性就消失了。
我已尝试重新设置以下属性:
- viewWillAppear:
- viewDidAppear:
- viewWillLayoutSubviews
- viewDidLayoutSubviews
...无济于事。此字符串何时重置为默认值?我怎样才能覆盖它?
【问题讨论】:
-
如何重置属性?
-
目前只是重复设置它的代码。
标签: ios fonts uilabel font-awesome nsattributedstring