簡體   English   中英

如何將自定義字體與映射字形一起使用?

[英]How to use custom font with mapped glyphs?

我在Illustrator中使用Fontself擴展制作了一些自定義 fonts。 我將 fonts 導出為otf文件,並將字形映射到字母鍵(a,b,c,d,..)上。 我想用它們來顯示我的editActionsForRowAt方法的圖標而不是字符串。

我按照蘋果(和其他指南)提供的步驟將 fonts 包含在我的項目中,所以沒有問題。

 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 -icon 並希望顯示它而不是“刪除”。

如何包含我的Ios-fonts.otf文件以顯示圖標而不是標題“刪除”?

首先,將字體文件導入您的項目。 其次,將字體文件名添加到您的 info.plist 文件(由應用程序提供的字體)中添加字符串值。 第三,將它們用於您的代碼中,例如:

使用這個 static function

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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM