Set the placeholder string for NSTextView

前端 未结 4 1914
鱼传尺愫
鱼传尺愫 2020-12-16 21:12

Is there any way to set the placeholder string for NSTextView like that in NSTextField? I have checked the property but couldn\'t find it. I have s

4条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-16 21:50

    Swift 4

    As it turns out, there already seems to be a placeholderAttributedString property in NSTextView that isn't exposed publicly. Thus, you can simply implement it in your own subclass and get the default placeholder behaviour (similar to NSTextField).

    class PlaceholderTextView: NSTextView {
         @objc var placeholderAttributedString: NSAttributedString?
    }
    

    And if this property will be made available in the future, you only need to use NSTextView instead of this subclass.

提交回复
热议问题