【问题标题】:Ios Swift Looping through Fonts provided by application in info.plistIos Swift 循环遍历 info.plist 中应用程序提供的字体
【发布时间】:2016-07-28 11:49:12
【问题描述】:

使用 Xcode 7 和 swift 2

我已经为 Info.plist 中的每个字体分配了一个字符串 -> 应用程序提供的字体 -> 数组

我如何遍历所有这些字体并在 for 循环中分配

我试过了:输出为零

var familyList = NSBundle.mainBundle().objectForInfoDictionaryKey("Fonts provided by application") as [String]

我遇到了下面的代码,它给了我所有姓氏的列表,我不需要。

我只需要使用我添加的字体进行循环。

for family: AnyObject in UIFont.familyNames() {
    println("Font Family: \(family)")
    for font: AnyObject in UIFont.fontNamesForFamilyName(family as NSString) {
        println("Font Name: \(font)")
    }
}

【问题讨论】:

  • 你可以使用let fonts = NSBundle.mainBundle.objectForInfoDictionaryKey("UIAppFonts") as NSArray(或者类似的东西,我不会说Swift,不确定语法)。然后,你应该能够得到我猜的字体名称。灵感来自:stackoverflow.com/questions/9805410/…

标签: ios fonts swift2 info.plist font-family


【解决方案1】:

要检索 Info.plist 中的信息,您可以使用 objectForInfoDictionaryKey()UIAppFonts 作为密钥。

我不会说 Swift,我不知道代码是否可以编译,但你应该能明白。

let fonts = NSBundle.mainBundle.objectForInfoDictionaryKey(UIAppFonts) as NSArray

这应该给你字体的数组。然后由您来构建UIFont 对象。

【讨论】:

  • 我对你的问题投了赞成票,因为你只是 SO 的新手,但因为即使你是新手,你也展示了你的尝试,而不仅仅是要求“免费代码”。
  • 谢谢 :-)... 我被困得更远了,现在我可以获取 .ttf 文件名,但无法从中获取字体系列。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-04-01
  • 2019-07-24
  • 1970-01-01
相关资源
最近更新 更多