iOS中的等宽字体是什么?

71

我希望在我的iOS应用程序中,为UILabel选择一种等宽字体。

很遗憾,我找不到一种适合的字体。即使是“American Typewriter”也并非等宽字体。请问在XCode中有哪些等宽字体可供使用?


3
Xcode本身不带字体。话虽如此,Xcode的默认字体至少在Snow Leopard和Lion版本中应该是Menlo。 - BoltClock
对于2018年来说,真正可用的只有Menlo和Courier两种字体。如今,iOS和Xcode内置了许多字体,并且一直可用(您可以在Xcode中轻松查看)。但是只有这两种等宽字体。 - Fattie
对于任何自定义字体和等宽数字字体,您可以使用以下代码来设置:// 设置自定义字体 let customFont = UIFont(name: "YourCustomFontName", size: 17.0) UILabel.appearance().font = customFont // 设置等宽数字字体 let monospacedFont = UIFont.monospacedDigitSystemFont(ofSize: 17.0, weight: .regular) UILabel.appearance().font = monospacedFont请注意,这将应用于整个应用程序中的所有标签。如果您只想在特定标签上使用自定义字体,请使用以下代码:yourLabel.font = customFont - Rubaiyat Jahan Mumu
http://docs.huihoo.com/apple/wwdc/2013/session_223__using_fonts_with_text_kit.pdf - Rubaiyat Jahan Mumu
11个回答

0

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

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

例子:

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

其他用途:

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接