Author
Travis Kirton


All Font Names

Accessing the individual fonts available on iOS is only a step removed from accessing the system’s family names. If you have a family name, you can grab its font names (as a String array) like this:

let fontNames = Font.fontNames(familyName)

Example

let scrollview = UIScrollView(frame: view.frame)
canvas.add(scrollview)

//Get all the family names
if let familyNamesArray = Font.familyNames() as? [String] {
    var point = Point(canvas.center.x, 10)

    //Cycle through all the family names, creating labels for each one
    for familyName in familyNamesArray.sort({ $0 < $1 }) {
        if let fontNames = Font.fontNames(familyName) as? [String] {
            for fontName in fontNames.sort({ $0 < $1 }) {
                let f = Font(name: fontName, size: 22.0)!
                let l = TextShape(text: fontName, font: f)!
                l.center = point
                point.y += 30
                scrollview.add(l)
                scrollview.contentSize = CGSize(width: 1, height: CGFloat(l.origin.y + l.height))
            }
        }
    }
}