【问题标题】:Including multiple fonts of the same family in an iPad application [closed]在 iPad 应用程序中包含同一系列的多种字体 [关闭]
【发布时间】:2011-08-11 17:25:58
【问题描述】:

当我必须包含多个相同字体系列的字体时,我在 iPad 应用程序中使用自定义字体时遇到问题。

基本上,有些字体会像其他字体一样呈现,尤其是粗体字体。 就我而言,我有以下四种字体:

中钨合金 (ok)
钨黑 (ok)
钨-粗体
钨-半粗体

系统发现所有这些其实我对mediumblack没有问题,但是当我选择bold时semibold 结果是 黑色 字体!

此问题会影响 UILabel 和 UITextField 等原生组件,但也会影响我在应用程序中使用的具有自定义 css 的 html 文档

我在项目资源和Info.plist文件中正确设置了所有内容,我什至尝试将字体转换为ttf格式但结果没有改变。

我正在使用 iOS sdk 4.2 for 和 iPad 应用程序,重要的是要知道在此操作系统之前(在 3.2 中)我的字体已正确呈现!

到目前为止,我发现的唯一可行的解​​决方案是编辑字体并为每个字体设置不同的字体系列,但这意味着在代码和 html 中需要做很多工作,所以我会避免这种情况.

我应该尝试什么?

【问题讨论】:

    标签: objective-c css ios4 fonts ipad


    【解决方案1】:

    我在阅读其他论坛时找到了解决方案。老实说,我认为这更像是一种解决方法,而不是真正的解决方案。

    我使用字体管理器工具 (Transtype pro) 来编辑字体元数据。我为每种字体设置了一个特定的“OT 字体系列”,其字段“PS 字体名称”的值相同。 这样可以避免框架在不接触代码的情况下混淆同族字体。

    丑陋,但它有效。

    【讨论】:

      【解决方案2】:

      我创建了一个方法,它读取某个系列的 fontsArray 中的字体描述并返回适当的字体。

      - (UIFont*) getFontWithFamilyName:(NSString*)familyName bold:(Boolean)bold italic:(Boolean)italic size:(uint)size {
          NSArray *fonts = [UIFont fontNamesForFamilyName:familyName];
          for (NSString *fname in fonts) {
             UIFont *font = [UIFont fontWithName:fname size:size];
             Boolean isBold = [[font description] rangeOfString:@"bold"].location != NSNotFound;
             Boolean isItalic = [[font description] rangeOfString:@"italic"].location != NSNotFound;
             if (isBold == bold && isItalic == italic) {
                return font;
             }
          }
          //-- font was not found, provide system font bold or normal
          if (bold) {
             return [UIFont boldSystemFontOfSize:size];
          } else {
             return [UIFont systemFontOfSize:size];
          }
      }
      

      【讨论】:

        猜你喜欢
        • 2011-03-24
        • 1970-01-01
        • 1970-01-01
        • 2020-11-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多