0

I am trying to create icons for each of my view controllers, but it is creating a question mark block as if it does not understand the image

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)

It is creating this image for each viewController: enter image description here

What is the problem?

Peter S
  • 827
  • 1
  • 8
  • 24

2 Answers2

1

Make sure you're importing .ttf file into your project and set the target of the files. Then, make sure you're updating your plist:

  • Import .ttf file into you project simply by draggin&drop, check "copy if needed" (Es. fontawesome-webfont.ttf)
  • Select you .ttf file and in the inspector select the icon above similar to a sheet, then in the section below (Target Membership) select your project as target if not
  • Finally check you plist and add the key "Fonts provided by application in your", and as item0 (it is an array) put the name of your fonts as value (es. fontawesome-webfont.ttf )

Refer to this link to see images of the previous instructions

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

Community
  • 1
  • 1
Andrew21111
  • 868
  • 8
  • 17
  • i'm using https://github.com/thii/FontAwesome.swift. So you are saying I should change the font? – Peter S Sep 28 '18 at 14:50
  • No, you don't have to change font. The library you're using is good, but it says: "Drag and drop all .otf and .swift files into your project". Did you do this ? did you check target? did you updated plist ? Please if not, try to do it! If you already did this, try to clear derived data, clean project and restart xcode ( be sure to open .xcworkspace, sometimes someone can miss this) – Andrew21111 Sep 28 '18 at 15:34
  • It says that OR install with Cocoapods I believe. – Peter S Sep 28 '18 at 20:03
  • Yes, but you should do the plist changes anyway – Andrew21111 Sep 28 '18 at 23:03
1

Use .solid instead of .brands. Brands uses just the font awesome brands library, for using icons like apple, github, etc.

Peter S
  • 827
  • 1
  • 8
  • 24
  • 1
    While this may provide an answer to the question, it would be far more useful if you provided some explanation as to why it does. – Nick Sep 29 '18 at 07:04