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
?
Asked
Active
Viewed 1,988 times
1

Ethan
- 18,584
- 15
- 51
- 72
-
this post might help if you haven't looked there yet http://stackoverflow.com/questions/24931311/xcode-style-placeholders-in-an-nstextview – Eugene Gordin Oct 08 '14 at 22:48
-
That's helpful, thanks! I thought there would be an easier way, like it is for text fields. – Ethan Oct 08 '14 at 23:34
-
See also: http://stackoverflow.com/questions/29428594/set-the-placeholder-string-for-nstextview – JWWalker May 27 '15 at 16:32
-
See me answer for Swift 3: http://stackoverflow.com/a/43028577/3184888 – JanApotheker Mar 26 '17 at 12:23
1 Answers
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