简体   繁体   中英

How to use custom font with mapped glyphs?

I made some custom fonts in Illustrator with the Fontself extension. I exported the fonts as an otf -file and mapped the glyphs on alphabetic keys (a,b,c,d,..). I wanted to use them to display an icon for my editActionsForRowAt method instead of a string.

I followed the steps provided by apple (and other guides) to include the fonts in my project, so no problem there.

 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]
    }

I mapped a Trash -icon on a and want to display it instead of "Delete".

How can I include my Ios-fonts.otf file to display an icon instead of the title "Delete"?

first, import the font file into your project. second, add font file name into your info.plist file (Fonts provided by application) add string value into it. third, use them into your code like:

use this 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)!
}

use them example:

textLabel.font = applyFonts_SFProText(style: .semiBold, size: 14)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM