Justin Copeland
Justin Copeland

Reputation: 1951

What is a monospace font in iOS?

Historic question 10+ yrs old. (UIFont.monospacedSystemFont now common.)


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?

Upvotes: 74

Views: 58821

Answers (11)

Leo Dabus
Leo Dabus

Reputation: 236370

SwiftUI

You can use Font's instance method monospacedDigit

Text("0123456789")
    .foregroundColor(.white)
    .font(Font.custom("San Francisco", size: 20).monospacedDigit())

Upvotes: 5

vin047
vin047

Reputation: 320

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)

Upvotes: 10

Hecot
Hecot

Reputation: 129

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

Upvotes: 0

Louis Lac
Louis Lac

Reputation: 6406

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)

Upvotes: 0

Reggie Pinkham
Reggie Pinkham

Reputation: 12718

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.

Upvotes: 85

codelark
codelark

Reputation: 12334

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.

Upvotes: 47

C. Bess
C. Bess

Reputation: 617

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

Upvotes: 6

Kurt Van den Branden
Kurt Van den Branden

Reputation: 12943

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

Upvotes: 3

Manuel
Manuel

Reputation: 878

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)

Upvotes: 38

mhulse
mhulse

Reputation: 4072

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

Upvotes: 10

Wil Macaulay
Wil Macaulay

Reputation: 517

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];

Upvotes: 15

Related Questions