【问题标题】:Custom Font not working in iOS 5自定义字体在 iOS 5 中不起作用
【发布时间】:2013-06-06 21:19:32
【问题描述】:

我在我的资源中添加了 Avenir-Next-LT-Pro-Demi-Condensed_5186.ttf 字体。还在我的 info.plist 中的应用程序提供的字体中添加了相同的内容。 在我的代码中,我设置了这样的字体,

titleLabel.font = [UIFont fontWithName:@"Avenir-Next-LT-Pro-Demi-Condensed_5186" size:10];

但这不适用于 ios 5 模拟器和设备。

【问题讨论】:

  • 首先检查你写的字体名称是否正确。
  • 我已经将字体名称设置为Avenir-Next-LT-Pro-Demi-Condensed_5186,因为文件名相同
  • @Akhildas 这不是一个正确的假设。检查使用 FontBook 打开字体时显示的名称。
  • 如果不能安装它们有什么用?
  • 您可以使用 UIFont 的类方法“familyNames”检查字体的正确名称。

标签: iphone ios ipad ios5 uifont


【解决方案1】:

试试这个,

The font name is not the font file name 

Avenir-Next-LT-Pro-Demi-Condensed_5186.ttf is a file name. simply double click the Avenir-Next-LT-Pro-Demi-Condensed_5186.ttf file it will automatically  open the font reader.Get the font name from top of the font reader navigation bar..

titleLabel.font = [UIFont fontWithName:@"Avenir Next LT Pro" size:10];

【讨论】:

    【解决方案2】:

    您必须检查有时与字体文件名不同的字体名称是什么...

    http://codefriends.blogspot.in/2012/04/adding-custom-font-in-xcode.html

    得到Add Custom Fonts In Xcode 4.1的答复

    【讨论】:

      【解决方案3】:

      按照下面给出的步骤进行

      1.确保在复制font 时选中"add to target" 复选框。

      2.首先选择你的font在finder中显示并双击不要确保你的font name必须和image一样

      这里的字体名称是“eurofurence light”

      3.在.plist文件中添加字体

      4.做完所有事情后检查你的字体---

       NSLog(@"%@",[UIFont fontNamesForFamilyName:@"Your font"]);
      

      根据font family 使用BoldItalic...

      希望对你有帮助

      【讨论】:

        【解决方案4】:

        我只是想在这个答案中补充一点,并不是所有的时间都遵循这个规则。最好的方法是在您的应用程序中注册字体并执行快速检查并验证字体名称。

        目标-c

         for (NSString *familyName in [UIFont familyNames]) {
            for (NSString *fontName in [UIFont fontNamesForFamilyName:familyName]) {
                NSLog(@"%@", fontName);
            }
        }
        

        斯威夫特

         for familyName in UIFont.familyNames() {
                for fontName in UIFont.fontNamesForFamilyName(familyName){
                    print(fontName)
                }
            }
        

        【讨论】:

          猜你喜欢
          • 2012-10-17
          • 1970-01-01
          • 1970-01-01
          • 2018-11-23
          • 1970-01-01
          • 2013-07-23
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多