This is strange.
This works:
titleLabel.font = UIFont(name: "OpenSans-Regular", size: 14)
This works:
attributedString.addAttribute(NSFontAttributeName, value:
UIFont(name: "OpenSans-Bold", size: 18)!,
range: ((attributedString.string as NSString).range(of: "Forgot your password? Reset it here")))
This doesn't. Gives a crash:
Unexpectedly found nil while unwrapping an Optional value
attributedString.addAttribute(NSFontAttributeName, value:
UIFont(name: "OpenSans-Regular", size: 18)!,
range: ((attributedString.string as NSString).range(of: "Email or password are incorrect."))).
First example shows that OpenSans-Regular works fine in the app. (Same font used in 3rd example).
Second example shows attributed string works fine with custom font.
Third example shows attributed string with custom font doesn't work.
I double checked, OpenSans-Regular I correctly copied in my project :
Project directory :
Copy bundle resources :
Info.plist :