【问题标题】:attributed text not working with custom font in xcode 7属性文本不适用于 xcode 7 中的自定义字体
【发布时间】:2015-08-19 13:51:14
【问题描述】:

我正在使用 Xcode 7。当使用带有自定义字体的属性文本时,它会显示在情节提要中,但无法在设备上运行。我尝试了以下代码:

var myMutableString = NSMutableAttributedString()

    let paragraphStyle = NSMutableParagraphStyle()
    paragraphStyle.lineSpacing = 8
    paragraphStyle.alignment = NSTextAlignment.Center

    myMutableString = NSMutableAttributedString(string: "\"Taking out my shorts and T-Shirt a night before has helped create a great morning routine for my walk\"", attributes: [NSFontAttributeName:UIFont(name: "Gotham Medium", size: 20.0)!])
    myMutableString.addAttribute(NSParagraphStyleAttributeName, value:paragraphStyle, range:NSMakeRange(0, myMutableString.length))

    quotesLabel.attributedText = myMutableString

【问题讨论】:

    标签: swift nsattributedstring swift2 xcode7


    【解决方案1】:

    确保您的应用包含 Gotham Medium 的字体文件。查看这篇关于 Common Mistakes With Adding Custom Fonts in iOS Apps 的精彩文章。

    1. 在 XCode 项目中包含字体
    2. 确保它们包含在目标中
    3. 仔细检查您的字体是否作为资源包含在您的捆绑包中
    4. 在您的应用程序列表中包含您的 iOS 自定义字体
    5. 查找字体名称
    6. 使用 UIFont 并指定字体名称

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-01-29
      • 2012-10-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-28
      相关资源
      最近更新 更多