NSMutableAttributedString
supports the method deleteCharacters(in:NSRange)
:
@IBOutlet weak var topLabel: NSTextField!
@IBOutlet weak var bottomLabel: NSTextField!
...
let textAttributes : [String : Any] = [
NSForegroundColorAttributeName : NSColor.blue,
NSFontAttributeName : NSFont(name: "Menlo", size: 12.0)!
]
let text = NSMutableAttributedString(string: "ABCDEF",
attributes: textAttributes)
topLabel.attributedStringValue = text
text.deleteCharacters(in: NSMakeRange(0,1))
bottomLabel.attributedStringValue = text
...
source
share