簡體   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”

我在項目中添加了自定義字體,並確保它在構建階段的“復制捆綁資源”中。 我還確保將其正確添加到plist文件中: plist中

但是當我為占位符文本設置函數時:

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")

我得到錯誤:

致命錯誤:解開Optional值時意外發現nil

為線

  NSFontAttributeName : UIFont(name: "NeutraText-Bold", size: 17)!

如果使用文件夾參考來保留字體,則需要確保將文件夾本身分配給目標。

在此處輸入圖片說明

如果遇到這種情況,請標記您擁有的頂部文件夾,然后在右側檢查目標成員資格是否正確標記。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM