I have a CFMutableAttributedString
set with attributes of key kCTForegroundColorAttributeName
and value of type CGColor
.
let attrString = NSMutableAttributedString(string: "foo bar")
let range = CFRange(location:0, length:6)
CFAttributedStringSetAttribute(attrString, range, kCTForegroundColorAttributeName, CGColor(red: 1.0, green: 0.0, blue: 0.0, alpha: 1.0))
I'm setting this String on NSTextStorage of NSTextView and none of the colors show.
However, for the same string doing this works -
// attrString is of type CFMutableAttributedString
let ret = NSMutableAttributedString(attributedString: attrString)
ret.addAttribute(.foregroundColor, value: NSColor.red, range: NSMakeRange(0, 10))
Why are attribute using Core Foundation attribute names not working? What would be an efficient way to set the foreground color using core foundation API that would work with NSTextView.
I'm using Swift 5 and OSX 10.15.2.