What is a monospace font in iOS?

前端 未结 10 1236
半阙折子戏
半阙折子戏 2020-12-02 19:41

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

相关标签:
10条回答
  • 2020-12-02 20:15

    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

    0 讨论(0)
  • 2020-12-02 20:23

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

    0 讨论(0)
  • 2020-12-02 20:24

    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)
    
    0 讨论(0)
  • 2020-12-02 20:29

    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)
    
    0 讨论(0)
  • 2020-12-02 20:29

    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];
    
    0 讨论(0)
  • 2020-12-02 20:34

    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.

    0 讨论(0)
提交回复
热议问题