Re: Calculating intrinsicContentSize for a NSTextField
Re: Calculating intrinsicContentSize for a NSTextField
- Subject: Re: Calculating intrinsicContentSize for a NSTextField
- From: Daryle Walker <email@hidden>
- Date: Sat, 18 Mar 2017 00:45:31 -0400
> On Mar 17, 2017, at 1:18 PM, Jeremy Hughes <email@hidden> wrote:
>
> I have a text field that I want to grow and shrink while it is being edited.
>
> In order to do that, I have overridden intrinsicContentSize and textDidChange in a subclass of NSTextField:
>
[SNIP]
>
> This works, but if I remove the call to attributedStringValue (whose result is discarded) the result of the following line fails to reflect changes in the bounds of the text, and the field fails to grow or shrink.
>
> Presumably, calling attributedStringValue has a side effect which changes the way that cellSize:forBounds: is calculated.
Looking at the “attributedStringValue” docs, "validateEditing()” is called as the side effect.
> Is there a way that I can get cellSize:forBounds: to return the correct value without relying on this side effect?
>
> An alternative way of calculating the intrinsic content size would be to use:
>
> attributedStringValue.boundingRect(with: size, options: .usesLineFragmentOrigin)
>
> but this fails to take account of cell insets.
—
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT com
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden