什么是 iOS 中的等宽字体?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9962994/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 17:39:22  来源:igfitidea点击:

What is a monospace font in iOS?

iosfonts

提问by Justin Copeland

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

我想在我的 iOS 应用程序中为我的 UILabel 使用等宽字体。

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

不幸的是,我找不到一个。甚至“美国打字机”实际上也不是等宽的。什么是 XCode 中可用的等宽字体?

采纳答案by codelark

Looking at an old listing of fonts shipped with iOSI see severalone monospace fonts.

查看iOS 附带的旧字体列表,我看到了几个等宽字体s

(eg. Andale Mono, Monaco,Courier New)

(例如Andale Mono、Monaco、Courier New)



For 2018 it's only Menlo and Courier.

2018 年只有 Menlo 和 Courier。

回答by Reggie Pinkham

iOS mono-spaced fonts

iOS 等宽字体

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

iosfonts.commaintain a list of all iOS fonts.

iosfonts.com维护了所有 iOS 字体的列表。

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

此网页会检测您安装的系统字体并返回一个相当全面的列表。

回答by Manuel

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)

回答by Wil Macaulay

Adobe just released a nice monospaced font Source Code Proin both TTF and OTF formats. It's licensed with the Open Font Licenseso 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.

Adobe 刚刚以 TTF 和 OTF 格式发布了一个不错的等宽字体Source Code Pro。它获得了Open Font License 的许可,因此可以在应用程序中免费使用,包括商业应用程序。您需要将字体文件作为资源添加到 Xcode 中,方法是将 info.plist 中的 UIAppFonts 键设置为指向 SourceCodeProRegular.ttf 文件。

Now in your code you can set, for example:

现在在您的代码中您可以设置,例如:

    self.textView.font = [UIFont fontWithName:@"Source Code Pro" size:14];

回答by mhulse

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:

扩展@reggie-pinkham 的回答,我构建了这个JS Bin 供人们用作实时测试页面;为了节省未来读者的一些时间,这里有一些在 Mavericks 上使用 iOS 模拟器的屏幕截图:

iPad Air, iOS 8.1

iPad Air,iOS 8.1

ipad-air-ios-8.1

ipad-air-ios-8.1

iPhone 6 plus, iOS 8.1

iPhone 6 plus,iOS 8.1

iphone-6-plus-ios-8.1

iphone-6-plus-ios-8.1

回答by C. Bess

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

如果您正在寻找数字的等宽字体,请尝试“Helvetica Neue”。

回答by Kurt Van den Branden

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

iOS 上可用的内置字体列表:http: //iosfonts.com。Courier 和 Menlo 似乎是那里唯一的等宽字体。

enter image description here

在此处输入图片说明

回答by vin047

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

从 iOS 13 开始,旧金山 (SF) Mono可用。找不到在界面构建器中设置它的方法,但通过代码它是:

let font = UIFont.monospacedSystemFont(ofSize: 17.0, weight: .regular)

回答by Louis Lac

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

您可以使用以下Font工厂方法以等宽访问系统字体:

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

Example:

例子:

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

Other usage:

其他用法:

let serifTitle = Font.system(.title, .serif)

回答by Hecot

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

与此同时,Apple 提供了一种很好的 Monospace 字体,可以在这里下载:Apple SFUI下面是如何将字体添加到 Xcode:将字体添加到 xcode