I will subclass NSTextView and using the following code to calculate the native size of the content so that the height of the text view grows with its contents in my auto layout limitations.
- (CGSize)intrinsicContentSize
{
return [[self layoutManager] usedRectForTextContainer:[self textContainer]].size;
}
This works, except for the initial call, where it returns (0,0) for the size.
If I call [self setNeedsLayout:YES]in my view after creating the text view and the size of the contents of the text view is invalid -layout, it will return the correct size for the new empty text view.
Is there a way to return the -intrinsicContentSizecorrect size for my new text view without updating my view layout?
source