-1

I have imported all types of my custom font into the Xcode but when I want to use it in UIFont I got Error

I use like below :

let appearance = UITabBarItem.appearance()
    let attributes = [NSAttributedString.Key.font: UIFont(name: "IRANSansMobile(FaNum)_Bold", size: 10),
                      NSAttributedString.Key.foregroundColor: UIColor.black]
    appearance.setTitleTextAttributes(attributes as [NSAttributedString.Key : Any], for: .normal)

when I delete _Bold from end of my font name it works correctly but not in bold style. please help me solve it

  • I guess that you used the filename instead of the postscript name? Install it in your Mac, open "Font Books.app", Select the bold font, then Cmd+I (show font information), and use the postscript name that is shown. Else, in iOS, add additional code to fetch all the fonts family enumerate and find your bold version. – Larme Sep 26 '18 at 10:34
  • For the `Fonts Book.app` version: https://apple.stackexchange.com/questions/79875/how-can-i-get-the-postscript-name-of-a-ttf-font-installed-in-os-x for the "coding" version: https://stackoverflow.com/questions/16788330/how-do-i-get-the-font-name-from-an-otf-or-ttf-file – Larme Sep 26 '18 at 10:35

1 Answers1

1

Code to print out your all available UIFonts. Check the name of the font family and font name. Use this name as your font name.

let fontFamilyNames = UIFont.familyNames()
        for familyName in fontFamilyNames {
            //Check the Font names of the Font Family
            let names = UIFont.fontNamesForFamilyName(familyName )
            // Write out the Font Family name and the Font's names of the Font Family
            print("Font == \(familyName) \(names)")
        }
user1376400
  • 614
  • 1
  • 4
  • 8