2

I added a custom font to my project and made sure it was in the "Copy Bundle Resources" in Build Phases. I also made sure it was added properly to the plist file: plist

but when I set up a function for placeholder text :

let attributes = [
  NSForegroundColorAttributeName: UIColor.white,
  NSFontAttributeName : UIFont(name: "NeutraText-Bold", size: 17)!
]


func placeHolder(_ text: String) -> (NSAttributedString){
  return NSAttributedString(string: text, attributes:attributes)
}

   signUpTextField.attributedPlaceholder = placeHolder("Sign Up")

I get the error:

fatal error: unexpectedly found nil while unwrapping an Optional value

for the line

  NSFontAttributeName : UIFont(name: "NeutraText-Bold", size: 17)!
SwiftyJD
  • 5,257
  • 7
  • 41
  • 92
  • Could you print all the fonts name ? http://stackoverflow.com/questions/33891959/available-fonts-on-ios It help to assure that your font is correctly added in the app, and also give the real name to use (which is in fact the postscript name of the font, which may be different from the "commercial one"). – Larme May 11 '17 at 21:03
  • It doesn't appear in the list when printed out, any idea why that could be? – SwiftyJD May 11 '17 at 21:09
  • Check all the steps from there: http://codewithchris.com/common-mistakes-with-adding-custom-fonts-to-your-ios-app/ ? – Larme May 11 '17 at 21:11
  • You have to add your font to Build Phases->Copy Bundle Resources – José Neto May 11 '17 at 21:12
  • http://stackoverflow.com/questions/21737788/custom-fonts-in-ios-7 should contain everything you have to check for. – Martin R May 11 '17 at 21:13

1 Answers1

0

If you are using folder reference to keep your fonts, you need to make sure that folder itself is assigned to your target.

enter image description here

If you case, mark the top folder you have, and on the right side, check if Target Membership is marked correctly.

Grzegorz Krukowski
  • 18,081
  • 5
  • 50
  • 71