【问题标题】:What values can be used in NSFont.TextStyleOptionKeyNSFont.TextStyleOptionKey 中可以使用哪些值
【发布时间】:2021-05-20 11:58:18
【问题描述】:

我找不到NSFont.TextStyleOptionKey 的有效值。

更具体地说,我想使用NSFont.preferredFont(forTextStyle:options:) 具有动态(动态点大小)类型,但我想更改字体的粗细。

【问题讨论】:

    标签: swift macos appkit nsfont dynamic-type-feature


    【解决方案1】:

    这些值是通过 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

    【讨论】:

    • 文档没有显示任何选项,Xcode 上的自动完成显示没有NSFont.TextStyleOptionKey 的键。它只显示.init(rawValue:)。也许我错过了什么?
    • 我想我可以使用NSFont.Weight 作为选项的值,但我主要想知道什么可以用作key
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-05-02
    • 2018-04-28
    • 2011-11-14
    • 2011-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多