4

I haven't been able to find valid values for NSFont.TextStyleOptionKey.

More specifically I want to use NSFont.preferredFont(forTextStyle:options:) to have dynamic (dynamic point size) type, but I would like to change the weight of the font.

XLE_22
  • 5,124
  • 3
  • 21
  • 72
vicegax
  • 4,709
  • 28
  • 37
  • Got any answers for this? @vauxhall – ohmprakash Jan 25 '22 at 12:13
  • 1
    @ohmprakash As of macOS 12 (Xcode 13.2.1) there seems to be no way of using this yet. My uneducated guess is that this just for getting ready to an upcoming update concerning TextKit 2 (announced on WWDC 21 but still with very little adoption, mainly only iOS so far). – vicegax Jan 26 '22 at 11:13
  • I would assume this is for options like the font design i.e. monospaced. But it is still nowhere to be found. – Daniel Aug 17 '23 at 16:05

1 Answers1

0

These values were revealed by autocomplete in 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

The jump to definition command shows this:

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
}

other options can be found here in the doc: https://developer.apple.com/documentation/appkit/nsfont/textstyleoptionkey

dldnh
  • 8,923
  • 3
  • 40
  • 52
  • 1
    The documentation shows me no options, and autocomplete on Xcode shows me no keys for `NSFont.TextStyleOptionKey`. It only shows me `.init(rawValue:)`. Maybe I'm missing something? – vicegax Mar 07 '21 at 10:56
  • I imagine I could use `NSFont.Weight` as a value for the options, but I'm mostly wondering what could be used as a `key`. – vicegax Mar 07 '21 at 10:58
  • yeah they literally answered nothing. `NSFont.systemFont(ofSize: size.value, weight: weight.textWeightNS)` use this instead of preferred if applicable – Nash Equilibrium May 07 '23 at 08:44