I have a strange problem with the sizeToFit method on an NSTextField.
I have an NSView where I create CALayer and NSTextField. I use the sizeToFit method to resize my CALayer to fit the field value. It works well, but when I insert a space, the text shifts to the left inside the field frame (see image below).
Both layers and text box borders are well placed (origin does not move).
Any hint about this would be much appreciated.

EDIT A frame update has the same behavior, even if sizeToFit is not used.
Sometimes it moves when you insert a space or sometimes it returns to the desired position when you insert a space.
The sublayer does not move from its source.
EDIT It seems that the NSTextField container has enough space to display. I found that there is enough space for this.
We cannot access the NSTextField container, so we add a large value to the line width (depending on the font size) before calling the frame update or [self sizeThatFits:stringSize]; and [self sizeToFit]; .
source share