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
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.