簡體   English   中英

在 iOS Swift 中將自定義字體設置為 UILabel

[英]Set Custom Font To UILabel in iOS Swift

在這里,我想將自定義字體(從后端獲取“字體名稱”)設置為 UILabel,而不在 xCode 項目中添加字體文件。

如果找到任何解決方案,請提供幫助。

目前我正在 iOS 中嘗試使用“Inkwell”。 這是鏈接-> https://github.com/ninjaprox/Inkwell

我遵循的步驟:

  1. 安裝 pod 'Inkwell', '~> 1.2'
  2. 在 AppDelegate 中添加了 Google API 密鑰,如 Inkwell.shared.APIKey = "Api key here"
  3. 導入“墨水瓶”
  4. 在 viewWillAppear 中,更新 label 字體:

     let font = Font(family: "Droid Sans", variant: .regular) fontOperation = Inkwell.shared.font(for: font, size: fontSize) { uifont in print("Font name -> \(String(describing: uifont))") self.lblTestFont.font = uifont?? self.defaultFont self.lblTestFont.text = "text" }

但是得到“字體名稱”為零。 字體操作失敗。

我該如何解決這個問題?

要在 iOS 應用程序中使用自定義字體,您需要在 info.plist 文件中添加這些字體,並在項目中添加這些字體。

完成所有這些步驟后,您可以使用以下代碼檢查我們的自定義字體是否可用。

//it will list all the fonts available 
for fontFamily in UIFont.familyNames {

   print(UIFont.fontNames(forFamilyName: fontFamily))
}

暫無
暫無

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

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