[英]Added custom font to project but when I try and use them I get a “fatal error: unexpectedly found nil while unwrapping an Optional value”
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
致命错误:解开Optional值时意外发现nil
for the line 为线
NSFontAttributeName : UIFont(name: "NeutraText-Bold", size: 17)!
If you are using folder reference to keep your fonts, you need to make sure that folder itself is assigned to your target. 如果使用文件夹参考来保留字体,则需要确保将文件夹本身分配给目标。
If you case, mark the top folder you have, and on the right side, check if Target Membership is marked correctly. 如果遇到这种情况,请标记您拥有的顶部文件夹,然后在右侧检查目标成员资格是否正确标记。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.