1

I know "Null Placeholder" for an NSTextField or an NSTextView can be set in Cocoa binding. Also, for an NSTextField, placeholder could be set in Xcode interface builder, or with aTextField.placeholderString = .... If I don't use Cocoa binding, how do I set the placeholder string for an NSTextView?

Ethan
  • 18,584
  • 15
  • 51
  • 72

1 Answers1

0

The placeholderAttributedString property in NSTextView isn't exposed publicly. Thus, you can simply implement it in your own subclass and get the default placeholder behavior:

1 - Create Subclass of NSTextView

class CustomTextView: NSTextView {
            var placeholderAttributedString: NSAttributedString?
        }

2 - Use in Your Viewcontroller

let attributes : [String : Any] = [NSFontAttributeName : NSFont(name: "HelveticaNeue-Light", size: 19)!, NSForegroundColorAttributeName : NSColor.green]
    yourTextView.placeholderAttributedString =  NSAttributedString(string: "Enter your Name", attributes: attributes)
Patrick R
  • 6,621
  • 1
  • 24
  • 27