Ios 如何将自定义字体与映射的图示符一起使用?
我用Fontself扩展在Illustrator中制作了一些自定义字体。我将字体导出为一个otf文件,并将字形映射到字母键上(a、b、c、d……)。我想用它们来显示我的editActionsForRowAt方法的图标,而不是字符串 我按照苹果提供的步骤(以及其他指南)将字体包括在我的项目中,因此没有问题Ios 如何将自定义字体与映射的图示符一起使用?,ios,swift,Ios,Swift,我用Fontself扩展在Illustrator中制作了一些自定义字体。我将字体导出为一个otf文件,并将字形映射到字母键上(a、b、c、d……)。我想用它们来显示我的editActionsForRowAt方法的图标,而不是字符串 我按照苹果提供的步骤(以及其他指南)将字体包括在我的项目中,因此没有问题 override func tableView(_ tableView: UITableView, editActionsForRowAt: IndexPath) -> [UITable
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上映射了一个垃圾桶-图标,并希望显示它而不是“删除”
如何包含Ios fonts.otf文件以显示图标而不是标题“Delete”?首先,将字体文件导入到项目中。 其次,将字体文件名添加到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)
首先,将字体文件导入到项目中。 其次,将字体文件名添加到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)
好问题。我认为这不可能直接实现(请注意,UITableViewRowAction自iOS 11以来就是UIContextualAction,但这并不会改变这个问题)。我认为最好的方法是将其呈现给图像,并使用该图像而不是文本(
UIContextualAction.image
)。这里有很多黑客解决方案,但我建议只渲染一个透明的图像:谢谢你的输入。我已经找到了很多解决方案。。全是黑透。我想一定有更简单的办法。因为我使用的是iOS 8,所以这可能是唯一的方法。谢谢!如果您使用UIContextualAction而不是UITableViewRowAction,这将有助于解决一个伟大的问题。我认为这不可能直接实现(请注意,UITableViewRowAction自iOS 11以来就是UIContextualAction,但这并不会改变这个问题)。我认为最好的方法是将其呈现给图像,并使用该图像而不是文本(UIContextualAction.image
)。这里有很多黑客解决方案,但我建议只渲染一个透明的图像:谢谢你的输入。我已经找到了很多解决方案。。全是黑透。我想一定有更简单的办法。因为我使用的是iOS 8,所以这可能是唯一的方法。谢谢!如果使用UIContextualAction而不是UITableViewRowAction,则会对您有所帮助