【问题标题】:Equivalent of UIFont .withSize in NSFont等价于 NSFont 中的 UIFont .withSize
【发布时间】:2017-12-11 22:06:46
【问题描述】:

我正在努力让 HandyUIKit 字符串扩展与 AppKit 一起使用。

什么是等价物

var font : UIFont    
font.withSize(font.pointSize * scriptedTextSizeRatio)

在 Appkit 和 NSFont 中?

var font : NSFont    
font.withSize(font.pointSize * scriptedTextSizeRatio)

这是我正在处理的代码部分:

 let capturedSubstring = unprocessedString.attributedSubstring(from: match.range(at: 1)).mutableCopy() as! NSMutableAttributedString
 let captureFullRange = NSRange(location: 0, length: capturedSubstring.length)
 capturedSubstring.addAttribute(.font, value: font.withSize(font.pointSize * scriptedTextSizeRatio), range: captureFullRange)

【问题讨论】:

  • 可可中的 AppKit?怎么样?

标签: swift nsfont


【解决方案1】:

NSFont 似乎没有像 UIFont 这样的等效方法 withSize

一种解决方案是使用:

var font: NSFont = ... // some font
var newFont = NSFont(descriptor: font.fontDescriptor, size: font.pointSize * scriptedTextSizeRatio)

请注意,newFont 是可选的,因此请根据需要检查结果。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-25
    • 2015-07-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多