【问题标题】:Cannot find System Bold Font for Attribute String iOS Xcode找不到属性字符串 iOS Xcode 的系统粗体字体
【发布时间】:2014-01-07 03:03:35
【问题描述】:

我是我的应用程序。我在很多地方都使用过 System Bold Font,这已成为我应用中的标准。

如果我使用属性字符串,默认字体是“Helvetica Neue”。在所有字体中,我搜索了 System Bold Font,但没有找到。

那么,如何在使用属性字符串时设置系统粗体?

【问题讨论】:

  • 我在界面生成器中找不到方法,但是我以编程方式使用 kCTFontEmphasizedSystemFontType 创建 CTFontRef 以放入 NSAttributedString 的属性字典中。您如何在代码中分配标签的属性文本属性?
  • @Bamsworld 我是从 Interface Builder 中完成的。你是对的,现在我将不得不使用 NSFontAttribute 作为值为“[UIFont boldSystemFontOfSize:size]”的 NSAttributedString 之一。

标签: ios xcode5 nsattributedstring


【解决方案1】:

您可以通过代码使其工作。在将属性字符串分配给 UILabel 时,我不得不面对完全相同的问题。我通过代码解决了它。见下面代码:

    NSString *s = @"Why so serious?";
    NSMutableAttributedString *str=[[NSMutableAttributedString alloc] initWithString:s];
    NSInteger _stringLength=[s length];
    UIColor *_red=[UIColor redColor];
    [str addAttribute:NSFontAttributeName value:[UIFont boldSystemFontOfSize:25] range:NSMakeRange(0, _stringLength)];
    [str addAttribute:NSStrokeColorAttributeName value:_red range:NSMakeRange(0, _stringLength)];
    [str addAttribute:NSStrokeWidthAttributeName value:[NSNumber numberWithFloat:-3.0] range:NSMakeRange(0, _stringLength)];
    self.aLabel.attributedText = str;

希望这会有所帮助。 :)

【讨论】:

  • 2017年还是这样吗?令人难以置信的是,我似乎在运行 XCode 8.2.1 时遇到了同样的问题...
  • 是的,它仍然是真的 :-(
猜你喜欢
  • 2015-07-23
  • 1970-01-01
  • 2015-10-17
  • 1970-01-01
  • 2013-12-03
  • 1970-01-01
  • 2016-05-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多