问题描述
我找不到 NSFont.TextStyleOptionKey
的有效值。
更具体地说,我想使用 NSFont.preferredFont(forTextStyle:options:)
来获得动态(动态点大小)类型,但我想更改字体的粗细。
解决方法
这些值由 XCode 中的自动完成显示:
NSFont.Weight.black
NSFont.Weight.heavy
NSFont.Weight.bold
NSFont.Weight.semibold
NSFont.Weight.medium
NSFont.Weight.regular
NSFont.Weight.light
NSFont.Weight.thin
NSFont.Weight.ultraLight
jump to definition
命令显示了这一点:
extension NSFont.Weight {
@available(macOS 10.11,*)
public static let ultraLight: NSFont.Weight
@available(macOS 10.11,*)
public static let thin: NSFont.Weight
@available(macOS 10.11,*)
public static let light: NSFont.Weight
@available(macOS 10.11,*)
public static let regular: NSFont.Weight
@available(macOS 10.11,*)
public static let medium: NSFont.Weight
@available(macOS 10.11,*)
public static let semibold: NSFont.Weight
@available(macOS 10.11,*)
public static let bold: NSFont.Weight
@available(macOS 10.11,*)
public static let heavy: NSFont.Weight
@available(macOS 10.11,*)
public static let black: NSFont.Weight
}
其他选项可以在文档中找到:https://developer.apple.com/documentation/appkit/nsfont/textstyleoptionkey