To the delight of font purists
everywhere, the iPhone system
interface uses Helvetica or a variant
thereof.
The original iPhone, iPhone 3G and
iPhone 3GS system interface uses
Helvetica. As first noted by the
always excellent DaringFireball, the
iPhone 4 uses a subtly revised font
called "Helvetica Neue."
DaringFireball also notes that this
change is related to the iPhone 4
display rather than the iOS 4
operating system and older iPhone
models running iOS 4 still use
Helvetica as the system font.
iPod models released prior to the
iPhone use either Chicago, Espy Sans,
or Myriad and use Helvetica after the
release of the iPhone.
If you're doing programatic customisation, don't hard code the system font. Use UIFont systemFontOfSize:, UIFont boldSystemFontOfSize: and UIFont italicSystemFontOfSize (Apple documentation).
This has become especially relevant since iOS 7, which changed the system font to Helvetica Neue.
This has become super especially relevant since iOS 9, which changed the system font again to San Francisco.
Here is some update for supporting iOS 7. It has Dynamic Font Size now.
For any and all apps that support “Dynamic Type,” users can select a
font size in iOS 7 that works system wide, simply by visiting the
"General" section under "Settings" and selecting "Font Size."
Setting a specific font in Swift is done like this:
let myFont = UIFont(name: "Helvetica", size: 17)
If you don't know the name, you can get a list of the available font names like this:
print(UIFont.familyNames())
Or an even more detailed list like this:
for familyName in UIFont.familyNames() {
print(UIFont.fontNamesForFamilyName(familyName))
}
But the system font changes from version to version of iOS. So it would be better to get the system font dynamically.
System font
let myFont = UIFont.systemFontOfSize(17)
But we have the size hard-coded in. What if the user's eyes are bad and they want to make the font larger? Of course, you could make a setting in your app for the user to change the font size, but this would be annoying if the user had to do this separately for every single app on their phone. It would be easier to just make one change in the general settings...
Dynamic font
let myFont = UIFont.preferredFont(forTextStyle: .body)
Ah, now we have the system font at the user's chosen size for the Text Style we are working with. This is the recommended way of setting the font. See Supporting Dynamic Type for more info on this.
You should always use the system defaults and not hard coding the font name because the default font could be changed by Apple at any time.
There are a couple of system default fonts(normal, bold, italic) with different sizes(label, button, others):
let font = UIFont.systemFont(ofSize: UIFont.systemFontSize)
let font2 = UIFont.boldSystemFont(ofSize: UIFont.systemFontSize)
let font3 = UIFont.italicSystemFont(ofSize: UIFont.systemFontSize)
beaware that the default font size depends on the target view (label, button, others)
Examples:
let labelFont = UIFont.systemFont(ofSize: UIFont.labelFontSize)
let buttonFont = UIFont.systemFont(ofSize: UIFont.buttonFontSize)
let textFieldFont = UIFont.systemFont(ofSize: UIFont.systemFontSize)