What Is the Nsfont Name for the Font 'Sf Mono'

What is the NSFont name for the font 'SF Mono'?

"SF Mono" is not a system font. You cannot select SF Mono outside of Terminal, Console and Xcode because it is not installed to the system.

The "SF Mono" in Terminal is a custom font in /Applications/Utilities/Terminal.app/Contents/Resources/Fonts/.

Similarly, the "SF Mono" in Console is another custom font in /Applications/Utilities/Console.app/Contents/Resources/Fonts.

Similarly, the "SF Mono" in Xcode is also a custom font in /Applications/Xcode.app/Contents/SharedFrameworks/DVTKit.framework/Resources/.

And of course you cannot bundle SF Mono alongside your program without violating Apple's copyright license:

This SF Mono Font (the “Apple Font”) is licensed to you by Apple Inc. (“Apple”) in consideration of your agreement to the following terms. If you do not agree with these terms, do not use the Apple Font.

You may use the Apple Font solely in conjunction with Apple-branded applications, including, but not limited to, Xcode, Terminal.app and Console.app. You may not embed or use the Apple Font in or with any other software applications or programs or other products and you may not use the Apple Font to create, develop, display or otherwise distribute any content, documentation, artwork or any other work product.

You may use the Apple Font only for the purposes described in this License or as otherwise expressly permitted by Apple in writing.

If the user has manually installed the font, it can be found with family name SF Mono, or the font name SFMono-Regular (similar for the other weights).

let f = NSFont(name: "SFMono-Regular", size: 12)

What's the mono-space font used on iPad's upcoming Swift Playgrounds app?

It's the new San Francisco Mono font. It's included in the Xcode 8 beta as the default font as well.

Name and size from NSFont

The name and size of NSFont are variables with setters and getters (@property) so you can easily get them:

object.fontName;
object.systemSize;

WatchKit SF monospaced number

Sample code:

UIFont *systemFont = [UIFont systemFontOfSize:20];  
UIFontDescriptor *monospacedNumberFontDescriptor = [systemFont.fontDescriptor fontDescriptorByAddingAttributes: @{
UIFontDescriptorFeatureSettingsAttribute: @[@{
UIFontFeatureTypeIdentifierKey: @6,
UIFontFeatureSelectorIdentifierKey: @0
}]
}];

UIFont *monospacedNumberSystemFont = [UIFont fontWithDescriptor:monospacedNumberFontDescriptor size:0];
NSMutableAttributedString *monospacedString = [[NSMutableAttributedString alloc] initWithString:@"1234567890"];
[monospacedString addAttribute:NSFontAttributeName value:monospacedNumberSystemFont range:NSMakeRange(0, monospacedString.string.length)];

[label setAttributedText:monospacedString];

Getting all characters from NSFont

If you really want to get all characters, you can use -coveredCharacterSet.

Otherwise, esp. if you want to get the glyph shapes, precise your Q. This will be a longer A.

How to get monospaced numbers in UILabel on iOS 9

Handy UIFont extension:

extension UIFont {
var monospacedDigitFont: UIFont {
let newFontDescriptor = fontDescriptor.monospacedDigitFontDescriptor
return UIFont(descriptor: newFontDescriptor, size: 0)
}
}

private extension UIFontDescriptor {
var monospacedDigitFontDescriptor: UIFontDescriptor {
let fontDescriptorFeatureSettings = [[UIFontDescriptor.FeatureKey.featureIdentifier: kNumberSpacingType,
UIFontDescriptor.FeatureKey.typeIdentifier: kMonospacedNumbersSelector]]
let fontDescriptorAttributes = [UIFontDescriptor.AttributeName.featureSettings: fontDescriptorFeatureSettings]
let fontDescriptor = self.addingAttributes(fontDescriptorAttributes)
return fontDescriptor
}
}

Usage with @IBOutlet properties:

@IBOutlet private var timeLabel: UILabel? {
didSet {
timeLabel.font = timeLabel.font.monospacedDigitFont
}
}

Latest version on GitHub.



Related Topics



Leave a reply



Submit