Bold part of an NSAttributedString without changing the font

If you bold by changing the `NSFontAttributeName` you’ll have to specify the font face. If you don’t want to change the font face, use the `NSStrokeWidthAttributeName` with a negative value:

let s = NSMutableAttributedString(string: "Text with some bold part")
s.addAttribute(.strokeWidth, value: NSNumber(value: -3.0), range: NSRange(15..<20))

Result:

Text with some bold part

Leave a Reply