A new font titled 'SF Mono' was introduced with Xcode 8.
It's a font that I personally find very readable, and I would like to use it in a NSTextView
. However, to set a font for an NSTextView
, it is required to use an NSFont
object. The problem is that I cannot seem to find the SF Mono
font in the list of available fonts through NSFontManager.shared().availableFonts
.
Does anyone know what the SF Mono
's programmatic name is for the initialisation of an NSFont (NSFont(name: String, size: CGFloat)
) for its typeface?
With iOS 13 and macOS 10.15 Apple made the new system fonts, including SF Mono and New York, available for developers.
You can get SF Mono using NSFont.monospacedSystemFont(ofSize: 0, weight: .regular)
.
Alternatively if you want to use the other system fonts you can use the NSFontDescriptor:
if let sfMonoDescriptor = NSFont.systemFont(ofSize: 0).fontDescriptor.withDesign(.monospaced) {
let sfMonoFont = NSFont(descriptor: sfMonoDescriptor, size: 0)!
}
For more information look at the WWDC Session Font Management and Text Scaling.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With