• <legend id='avknQ'><style id='avknQ'><dir id='avknQ'><q id='avknQ'></q></dir></style></legend>
  • <small id='avknQ'></small><noframes id='avknQ'>

    1. <tfoot id='avknQ'></tfoot>

        <i id='avknQ'><tr id='avknQ'><dt id='avknQ'><q id='avknQ'><span id='avknQ'><b id='avknQ'><form id='avknQ'><ins id='avknQ'></ins><ul id='avknQ'></ul><sub id='avknQ'></sub></form><legend id='avknQ'></legend><bdo id='avknQ'><pre id='avknQ'><center id='avknQ'></center></pre></bdo></b><th id='avknQ'></th></span></q></dt></tr></i><div id='avknQ'><tfoot id='avknQ'></tfoot><dl id='avknQ'><fieldset id='avknQ'></fieldset></dl></div>
          <bdo id='avknQ'></bdo><ul id='avknQ'></ul>

      1. Xcode:在动态框架中使用自定义字体

        时间:2023-05-19
          <bdo id='RlUkd'></bdo><ul id='RlUkd'></ul>
            • <small id='RlUkd'></small><noframes id='RlUkd'>

                <i id='RlUkd'><tr id='RlUkd'><dt id='RlUkd'><q id='RlUkd'><span id='RlUkd'><b id='RlUkd'><form id='RlUkd'><ins id='RlUkd'></ins><ul id='RlUkd'></ul><sub id='RlUkd'></sub></form><legend id='RlUkd'></legend><bdo id='RlUkd'><pre id='RlUkd'><center id='RlUkd'></center></pre></bdo></b><th id='RlUkd'></th></span></q></dt></tr></i><div id='RlUkd'><tfoot id='RlUkd'></tfoot><dl id='RlUkd'><fieldset id='RlUkd'></fieldset></dl></div>
                  <tfoot id='RlUkd'></tfoot>

                  <legend id='RlUkd'><style id='RlUkd'><dir id='RlUkd'><q id='RlUkd'></q></dir></style></legend>
                    <tbody id='RlUkd'></tbody>
                • 本文介绍了Xcode:在动态框架中使用自定义字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我在框架中添加了自定义字体.我按照所有步骤操作,但它不起作用.

                  I added custom font to a framework. I followed all the steps, but it doesn't work.

                  我可以在 Interface Builder 中设置字体,但是当我构建项目时,它不会在模拟器/设备上显示此字体.

                  I am able to set the font in Interface Builder, but when I build the project it doesn't show this font on the simulator/device.

                  推荐答案

                  我来的有点晚了,但是我采用了 PetahChristian 的解决方案,并以扩展的形式创建了一个 Swift 版本.这对我有用.我发现,当您尝试使用字体名称和大小使用常规方式获取字体时,它总是在字体文件的主包中查找,并且没有将包标识符作为参数的方法.如果苹果能做出来就好了.

                  I'm here a bit late, but I took PetahChristian's solution and created a Swift version in the form of an extension. This is working for me. I've found that when you try to get a font using a font name and a size using the regular way that it always looks in the main bundle for the font file, and there's no method that takes a bundle identifier as a parameter. It would be nice if Apple would make one.

                  斯威夫特:

                  public extension UIFont {
                  
                      public static func jbs_registerFont(withFilenameString filenameString: String, bundle: Bundle) {
                  
                          guard let pathForResourceString = bundle.path(forResource: filenameString, ofType: nil) else {
                              print("UIFont+:  Failed to register font - path for resource not found.")
                              return
                          }
                  
                          guard let fontData = NSData(contentsOfFile: pathForResourceString) else {
                              print("UIFont+:  Failed to register font - font data could not be loaded.")
                              return
                          }
                  
                          guard let dataProvider = CGDataProvider(data: fontData) else {
                              print("UIFont+:  Failed to register font - data provider could not be loaded.")
                              return
                          }
                  
                          guard let font = CGFont(dataProvider) else {
                              print("UIFont+:  Failed to register font - font could not be loaded.")
                              return
                          }
                  
                          var errorRef: Unmanaged<CFError>? = nil
                          if (CTFontManagerRegisterGraphicsFont(font, &errorRef) == false) {
                              print("UIFont+:  Failed to register font - register graphics font failed - this font may have already been registered in the main bundle.")
                          }
                      }
                  
                  }
                  

                  用法示例:

                  UIFont.jbs_registerFont(
                      withFilenameString: "Boogaloo-Regular.ttf",
                      bundle: Bundle(identifier: "com.JBS.JBSFramework")!
                  )
                  

                  这篇关于Xcode:在动态框架中使用自定义字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何在另一个框架内添加一个框架(Umbrella Framework) 下一篇:在 Xcode 4 中添加框架

                  相关文章

                    <tfoot id='6j7dk'></tfoot>

                    <i id='6j7dk'><tr id='6j7dk'><dt id='6j7dk'><q id='6j7dk'><span id='6j7dk'><b id='6j7dk'><form id='6j7dk'><ins id='6j7dk'></ins><ul id='6j7dk'></ul><sub id='6j7dk'></sub></form><legend id='6j7dk'></legend><bdo id='6j7dk'><pre id='6j7dk'><center id='6j7dk'></center></pre></bdo></b><th id='6j7dk'></th></span></q></dt></tr></i><div id='6j7dk'><tfoot id='6j7dk'></tfoot><dl id='6j7dk'><fieldset id='6j7dk'></fieldset></dl></div>

                      <small id='6j7dk'></small><noframes id='6j7dk'>

                    1. <legend id='6j7dk'><style id='6j7dk'><dir id='6j7dk'><q id='6j7dk'></q></dir></style></legend>

                      • <bdo id='6j7dk'></bdo><ul id='6j7dk'></ul>