简体   繁体   English

在项目中添加了自定义字体,但是当我尝试使用它们时,出现“严重错误:在展开可选值时意外发现nil”

[英]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文件中: 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.

相关问题 尝试获取联系电话时,出现错误“致命错误:在展开可选值时意外发现nil” - I got an error “fatal error: unexpectedly found nil while unwrapping an Optional value” when I try to get a phone number in contact 当我实现Parse时,我得到“致命错误:在展开可选值时意外发现nil” - When I implement Parse I get “fatal error: unexpectedly found nil while unwrapping an Optional value” 当我尝试访问它们时,IBOutlet变量返回nil。 错误:线程1:致命错误:展开一个可选值时意外发现nil - IBOutlet variables return nil when I try to access them. Error: Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value 当我尝试使用userDefaults保存为ui颜色时,Xcode给我以下错误:致命错误:在展开可选值时意外发现nil - When I try to save to ui colors with userDefaults, Xcode gives me the error : Fatal error: Unexpectedly found nil while unwrapping an Optional value 迅速-播放声音时出现错误“严重错误:在展开可选值时意外发现nil” - Swift - While playing sound I get error “fatal error: unexpectedly found nil while unwrapping an Optional value” 遇到:展开一个Optional值时意外发现nil,当我尝试使其变为可选值时,出现另一个错误 - Running into: Unexpectedly found nil while unwrapping an Optional value, when I try to make it optional, I get another error 运行我的应用程序时出现此错误。 线程1:致命错误:展开一个可选值时意外地找到零 - I get this error when i run my app. Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value 解包可选的 IBOutlet 时出现错误(线程 1:致命错误:解包可选值时意外发现 nil) - I have an error when unwrapping an optional IBOutlet (Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value) 当我尝试通过AVAssetImageGenerator获取CGImage时,“在展开可选值时意外发现nil” - “unexpectedly found nil while unwrapping an Optional value” when I try to get a CGImage by AVAssetImageGenerator swift 4 中的自定义字体导致致命错误:在展开可选值时意外发现 nil - Custom font in swift 4 make Fatal error: Unexpectedly found nil while unwrapping an Optional value
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM