xcode 7 中的属性文本不适用于自定义字体

attributed text not working with custom font in xcode 7

我正在使用 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

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

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