FontAwesome UITabBarItem 显示不正确

FontAwesome UITabBarItem not displaying correctly

我正在尝试为我的每个视图控制器创建图标,但它正在创建一个问号块,就好像它不理解图像一样

let settings = UINavigationController(rootViewController: SettingsController())
let individual = IndividualAthleteController()

var items: [FontAwesome: UIViewController] = [.slidersH: settings,.user: individual]
for (iconString, viewController) in items {

    let icon = UIImage.fontAwesomeIcon(name: iconString, style: .brands, textColor: .black, size: CGSize(width: 30, height: 30))
    let tabBar = UITabBarItem(title: viewController.title, image: icon, selectedImage: icon)
    items[iconString]!.tabBarItem = tabBar
}
viewControllers = Array(items.values)

它正在为每个 viewController 创建此图像:

有什么问题?

确保将 .ttf 文件导入项目并设置文件的目标。然后,确保您正在更新您的 plist:

  • 只需拖放即可将 .ttf 文件导入到您的项目中,勾选“需要时复制”(Es. fontawesome-webfont.ttf)
  • Select 你的 .ttf 文件和检查器 select 上面的图标类似于 sheet,然后在下面的部分(目标会员)select 你的项目作为目标,如果不是
  • 最后检查你的 plist 并添加键“你的应用程序提供的字体”,作为 item0(它是一个数组)将你的字体名称作为值(es.fontawesome-webfont.ttf)

参考this link查看之前说明的图片

If you're using this library Vaberer/Font-Awesome-Swift, make sure you're doing the same as the above steps

NOTE: If you're not using the Vaberer library, give it a chance

使用 .solid 而不是 .brands。 Brands 仅使用字体很棒的品牌库,用于使用 apple、github 等图标