69

I want a monospace font for my UILabel in my iOS application.

Unfortunately, I could not find one. Even "American Typewriter" was not actually monospaced. What is a monospace font available in XCode?

Léo Natan
  • 56,823
  • 9
  • 150
  • 195
Justin Copeland
  • 1,891
  • 5
  • 23
  • 27
  • 3
    Xcode itself doesn't ship with fonts. That said, the default font for Xcode should be Menlo at least as of Snow Leopard and Lion. – BoltClock Apr 01 '12 at 08:35
  • For **2018** it's really only Menlo and Courier. These days, iOS and Xcode have a long list of fonts built in and always available (you can easily see it in Xcode). There are only the two monospace fonts. – Fattie Feb 03 '18 at 18:47
  • https://stackoverflow.com/a/50792536/3939807 For any custom font and monospaced number font – Rubaiyat Jahan Mumu Jun 11 '18 at 07:53
  • http://docs.huihoo.com/apple/wwdc/2013/session_223__using_fonts_with_text_kit.pdf – Rubaiyat Jahan Mumu Jun 11 '18 at 08:06

11 Answers11

82

iOS mono-spaced fonts

Courier  
Courier-Bold  
Courier-BoldOblique  
Courier-Oblique  
CourierNewPS-BoldItalicMT  
CourierNewPS-BoldMT  
CourierNewPS-ItalicMT  
CourierNewPSMT  
Menlo-Bold  
Menlo-BoldItalic  
Menlo-Italic  
Menlo-Regular

iosfonts.com maintain a list of all iOS fonts.

This webpage detects your installed system fonts and returns a fairly comprehensive list.

Community
  • 1
  • 1
Reggie Pinkham
  • 11,985
  • 4
  • 38
  • 36
  • Please note "Menlo" and "Menlo-Regular" are Not fully mono-spaced where "Menlo-Bold" is indeed mono-spaced. For the two fonts I am seeing a small variation in width when displaying a "2" instead of other digits. Observed with both Simulator XCode 12.4 and iOS 14.4 – dmind Apr 08 '21 at 22:32
47

Looking at an old listing of fonts shipped with iOS I see several one monospace fonts.

(eg. Andale Mono, Monaco, Courier New)


For 2018 it's only Menlo and Courier.

Iulian Onofrei
  • 9,188
  • 10
  • 67
  • 113
codelark
  • 12,254
  • 1
  • 45
  • 49
38

If your intent is to display numbers and you don't care about the specific font used, you can do this:

UIFont.monospacedDigitSystemFontOfSize(
    UIFont.systemFontSize(),
    weight: UIFontWeightRegular)
Manuel
  • 868
  • 8
  • 9
  • iOS 9 or newer, sadly – Dan Rosenstark Jan 15 '16 at 00:29
  • 1
    I tried this for a timer counting up which uses a SKSpriteLabel, but the label still "jumps around" with said "monospaced" system font. :-( – Jonny Jan 25 '16 at 09:16
  • Menlo it is, then. – Stonetip May 10 '16 at 02:52
  • 1
    In iOS 10.2, using UIFont.monospacedDigitSystemFont(ofSize:weight:) works for me. My "digital timer" UILabel does not "jump around". Either Apple has fixed it since @Jonny tried it, or UILabel does not have the bug which SKSpriteLabel has. – Jerry Krinock Dec 21 '16 at 15:37
  • Ah, now I see a problem, possibly why it did not work for Jonny. It turns out that, if you are using **size class customization** in the Attributes Inspector of Interface Builder, and put Manuel's code in `viewDidLoad()`, your code will not be effective because, at runtime, the customization is apparently done *after* `viewDidLoad()` runs, thus changing it back to the regular system font. I just posted a [demo project with workaround for this behavior](https://github.com/jerrykrinock/CountdownUILabel). – Jerry Krinock Jan 09 '17 at 16:42
  • The best thing about this solution is that it is actually (currently on iOS11) using SFUI rather than one of the other mono fonts in the system. Will look far more uniform when mixed with other text than using Menlo or Courier! – siburb Apr 13 '18 at 02:48
  • What about iOS version less than 9.0? Using regular system font ? – Rubaiyat Jahan Mumu Jun 11 '18 at 05:13
  • 1
    this font IS NOT equal widths. bizarre. – Fattie Jun 17 '19 at 20:26
15

Adobe just released a nice monospaced font Source Code Pro in both TTF and OTF formats. It's licensed with the Open Font License so it is available for free use within applications, including commercial applications. You will need to add the font file as a resource in Xcode, by setting the UIAppFonts key in the info.plist to point to the SourceCodeProRegular.ttf file.

Now in your code you can set, for example:

    self.textView.font = [UIFont fontWithName:@"Source Code Pro" size:14];
Wil Macaulay
  • 507
  • 3
  • 12
10

Expanding upon @reggie-pinkham's answer, I built this JS Bin for folks to use as a live test page; to save future reader's some time, here's a few screen shots using iOS Simulator on Mavericks:

iPad Air, iOS 8.1

ipad-air-ios-8.1

iPhone 6 plus, iOS 8.1

iphone-6-plus-ios-8.1

Community
  • 1
  • 1
mhulse
  • 4,062
  • 6
  • 28
  • 35
8

As of iOS 13, San Francisco (SF) Mono is available. Couldn't find a way to set this in interface builder, but by code it's:

let font = UIFont.monospacedSystemFont(ofSize: 17.0, weight: .regular)
vin047
  • 260
  • 3
  • 12
  • Here is how to add the fonts to Xcode: Add fonts to xcode https://developer.apple.com/documentation/uikit/text_display_and_fonts/adding_a_custom_font_to_your_app?language=objc – Hecot Apr 06 '20 at 11:18
5

If you're looking for a monospace font for numbers, then try "Helvetica Neue".

C. Bess
  • 567
  • 7
  • 10
4

SwiftUI

You can use Font's instance method monospacedDigit

Text("0123456789")
    .foregroundColor(.white)
    .font(Font.custom("San Francisco", size: 20).monospacedDigit())
Leo Dabus
  • 229,809
  • 59
  • 489
  • 571
3

A list of built-in fonts available on iOS: http://iosfonts.com. Courier and Menlo seem to be the only monospace fonts in there.

enter image description here

Kurt Van den Branden
  • 11,995
  • 10
  • 76
  • 85
0

You can access system fonts in monospaced with the following Font factory method:

static func system(Font.TextStyle, design: Font.Design) -> Font

Example:

let monospacedBody = Font.system(.body, .monospaced)

Other usage:

let serifTitle = Font.system(.title, .serif)
Louis Lac
  • 5,298
  • 1
  • 21
  • 36
0

In the meantime there is a good Monospace font available from Apple, that can be downloaded here: Apple SFUI Here is how to add the fonts to Xcode: Add fonts to xcode

Hecot
  • 89
  • 1
  • 11