Reputation: 682
I've already figured out the solution. However, I couldn't find anything that addressed the problem.
Problem:
I wanted to customize the placeholder text in NSTextField
, but it would appear upside down.
let string = "Enter \"Script\" Here"
var attributes: Dictionary<NSAttributedString.Key, Any> = [:]
attributes[NSAttributedString.Key.foregroundColor] = NSColor.secondaryLabelColor
attributes[NSAttributedString.Key.font] = NSFont(name: "Arial", size: 15.0)!
let attributedString = NSAttributedString(string: string, attributes: attributes)
self.scriptTextField.placeholderAttributedString = attributedString
Upvotes: 2
Views: 313
Reputation: 682
Solution:
I had to add self.scriptTextField.wantsLayer = true
.
let string = "Enter \"Script\" Here"
var attributes: Dictionary<NSAttributedString.Key, Any> = [:]
attributes[NSAttributedString.Key.foregroundColor] = NSColor.secondaryLabelColor
attributes[NSAttributedString.Key.font] = NSFont(name: "Arial", size: 15.0)!
let attributedString = NSAttributedString(string: string, attributes: attributes)
self.scriptTextField.placeholderAttributedString = attributedString
self.scriptTextField.wantsLayer = true
Upvotes: 1