Equivalent of UIFont .withSize in NSFont

267 Views Asked by At

I am working on getting the HandyUIKit String extensions working with AppKit.

What is the equivalent for

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

in Appkit and NSFont?

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

Here is the code section I am working on:

 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)
1

There are 1 best solutions below

0
On BEST ANSWER

NSFont doesn't seem to have an equivalent method withSize like UIFont.

One solution would be to use:

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

Note that newFont will be optional so check the result as needed.