David
David

Reputation: 682

How to Fix "Upside Down" / "Inverted" / "Flipped" Text in placeholderAttributedString of NSTextField

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

Upside Down Text

Upvotes: 2

Views: 313

Answers (1)

David
David

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

Right Side Up Text

Upvotes: 1

Related Questions