3

Using Xcode 7 and swift 2

I have assigned a string for each font in Info.plist -> Fonts provided by application -> Array

How do i loop through all these fonts and assign in for loop

I tried : Output was nil

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

I came across below code which gives me list of all family names, which i dont need.

I Need same to loop only with fonts i have added.

for family: AnyObject in UIFont.familyNames() {
    println("Font Family: \(family)")
    for font: AnyObject in UIFont.fontNamesForFamilyName(family as NSString) {
        println("Font Name: \(font)")
    }
}
Community
  • 1
  • 1
Sujay U N
  • 4,974
  • 11
  • 52
  • 88
  • You can use `let fonts = NSBundle.mainBundle.objectForInfoDictionaryKey("UIAppFonts") as NSArray` (or something similar, I don't speak Swift, not sure about the syntax). Then, you should be able to get the font names I guess. Inspired from: http://stackoverflow.com/questions/9805410/getting-data-from-the-info-plist – Larme Jul 28 '16 at 11:55

1 Answers1

2

To retrieve the info in the Info.plist, you can use objectForInfoDictionaryKey() with UIAppFonts for the key.

I don't speak Swift, and I don't know if the code compile, but you should be able to get the idea.

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

That should give you the array of the fonts. It's up to you then to construct the UIFont objects.

Larme
  • 24,190
  • 6
  • 51
  • 81
  • I voted up your question because you are only new on SO, but because even if you are new, you showed your attempts and not just asked for "free code". – Larme Jul 28 '16 at 12:46
  • Thank You :-)... I got stuck further, Now i am able to get .ttf file names, but not able to get the font family out of this. – Sujay U N Jul 28 '16 at 12:57