Multi-line NSTextField not working

前端 未结 2 811
感情败类
感情败类 2021-01-13 03:10

I have been trying to get a multi-line NSTextField to lay out automatically using preferredMaxLayoutWidth. I can’t figure out why this doesn’t work

2条回答
  •  爱一瞬间的悲伤
    2021-01-13 04:13

    OK. So it turns out that when an NSTextField is in edit mode, a secret NSTextView (aka the “field editor”) takes over for the editing portion. Text changes are not synced back to the text field until editing has ended. This explains why my sample code only works in non-edit mode.

    You can force the sync to occur by accessing the NSTextField.stringValue property. This is what I’ve done in a NSTextField subclass. I also provided my own implementation of intrinsicContentSize because Apple’s implementation doesn’t work in edit mode and is buggy in non-edit mode.

提交回复
热议问题