我试图更改占位文本的颜色。以下代码不起作用:
let color = NSColor.redColor()
let attrs = [NSForegroundColorAttributeName: color]
let placeHolderStr = NSAttributedString(string: "My placeholder", attributes: attrs)
myTextField.placeholderAttributedString = placeHolderStr
我遇到了错误-[NSTextField setPlaceholderAttributedString:]: unrecognized selector sent to instance
。有什么办法可以改变占位符的颜色吗?
更新:
(myTextField.cell() as NSTextFieldCell).placeholderAttributedString = placeHolderStr
更新2: 嗯,它改变了颜色,但如果文本字段获得焦点,占位符字体大小会变小,非常奇怪。