如何将自定义字体与映射字形一起使用?

时间:2020-04-21 07:52:10

标签: ios swift

我用 Fontself 扩展名在 Illustrator 中制作了一些自定义字体。我将字体导出为 otf 文件,并将字形映射到字母键(a,b,c,d,..)。我想使用它们为我的 editActionsForRowAt 方法显示图标,而不是字符串。

我遵循了apple(和其他指南)提供的步骤,将字体包含在我的项目中,所以在那里没有问题。

 override func tableView(_ tableView: UITableView, editActionsForRowAt: IndexPath) -> [UITableViewRowAction]? {
        let doc = documentations.value[editActionsForRowAt.row]

        let deleteBtn = UITableViewRowAction(style: .normal, title: "Delete") { action, index in
            try? Documentation.db.cascadedDelete(documentationId: doc.id)
            var ary = self.documentations.value
            ary.remove(at: editActionsForRowAt.row)
            self.documentations.accept(ary)
        }
        deleteBtn.backgroundColor = UIColor.init(hexString: "#e53935")

        return [deleteBtn]
    }

我在 a 上映射了 Trash -图标,并希望显示它而不是“ Delete”。

如何包含我的 Ios-fonts.otf 文件来显示图标,而不显示标题“ Delete”?

1 个答案:

答案 0 :(得分:0)

首先,将字体文件导入您的项目。 其次,在您的info.plist文件中添加字体文件名(应用程序提供的字体),在其中添加字符串值。 第三,将它们用于您的代码中,例如:

使用此静态函数

enum FontStyle: String {
    case regular = "Regular"
    case semiBold = "SemiBold"
    case medium = "Medium"
}

static func applyFonts_SFProText(style: FontStyle, size: CGFloat) -> UIFont {
    return UIFont(name: "SFProText-\(style.rawValue)", size: size)!
}

使用示例:

textLabel.font = applyFonts_SFProText(style: .semiBold, size: 14)
相关问题