0

I have an NSTextfield with AutoLayout enabled, inside a NSTableviews Cell. So the textfield (and the cell that holds it) grows everytime I add "\n", for example by pressing Enter. But it only works for that manual kind of word wrap. If the TextFields width is reached, the line wraps automatically, but the Textfields height doesn't change.

Now I saw a few possible solutions with subclassing NSTextField and overriding intrinsicContentSize. Here:

How to let NSTextField grow with the text in auto layout?

getting a NSTextField to grow with the text in auto layout?

but that isn't working for me. It just does nothing. Maybe the problem is in the way I set my constraints within the tableviewcell, but then if it's growing successfully when doing a manual word wrap, there also should be a way to do that when it wraps automatically.

I'd be really grateful for help. If you need further informations I can upload my code somewhere.

Swift Dev Journal
  • 19,282
  • 4
  • 56
  • 66

2 Answers2

0

You need to set desired width to "First Runtime Layout Width" for that label. You find that in Size Inspector (small ruler icon in the right pane).

Gergely
  • 3,025
  • 2
  • 14
  • 13
0

Use these lines when you set value for the textfield

layoutSubtreeIfNeeded()
invalidateIntrinsicContentSize()