Search code examples
iosswiftcocoa-touch

How to access the iOS system font programmatically


I am trying to change the font size of the title of a navigation bar. I know I can set its attributes using:

var attributes = [ NSForegroundColorAttributeName: UIColor.blackColor(), NSFontAttributeName: UIFont(name: "the font name", size: 18)! ]

...

 self.navigationController?.navigationBar.titleTextAttributes = attributes

What I cannot seem to find is the correct 'System' font name.

I was after the default, a.k.a System, font name. I tried printing all the available fonts only to discover it does not belong to a family and does not seem to have an explicit name.


Solution

  • I think you need:

    NSFontAttributeName : UIFont.systemFontOfSize(19.0)
    

    Or the bold version:

    NSFontAttributeName : UIFont.boldSystemFontOfSize(19.0)
    

    See this guide for more info on user interface guidelines and fonts.