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
There is an another solution for making the NSTextField multiline with using auto constraints and Interface Builder.
Wraps
from LayoutCharacter Wrap
from Line Break optionunchecked
And add below sample constraints
with the constants that you want. And don't add any specific height constraint.
Below some screenshots which might be helpful.
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.