Re: Set font on NSTextView that uses bindings?
Re: Set font on NSTextView that uses bindings?
- Subject: Re: Set font on NSTextView that uses bindings?
- From: Andy Lee <email@hidden>
- Date: Thu, 19 May 2016 10:00:38 -0400
Suggestion 1: A few weeks ago I ran into the same problem. I stumbled onto a kludge that seems to work, which was to put some text into the text view in IB. It can be spaces, it can be anything, as long as it's non-empty and it uses the desired font. It seems that the bindings mechanism is then able to replace that text while preserving the font. I have the rich text option turned off, and I'm using the Value binding of the NSTextView.
Suggestion 2: I found a different kludge that I used 5 years ago where I send setFont: to the text view, in code.. Haven't retested to see if that still works, and I don't actually have the whole project handy, just an email where I describe the workaround. I do it in windowControllerDidLoadNib:, which is an NSDocument method. If you're not using NSDocument it might work to call setFont: in some other "DidLoad" method.
Idle speculation: It seems NSTextView doesn't quite do what one would guess, font-wise, when it's empty. I'm too lazy right this moment to explore, but maybe it actually contains an attributed string of zero length that has the wrong font, not the one you thought you'd told it to use.
Possibly related: In the Stickies app I sometimes create a new note, paste some text, and realize I've pasted in rich text where I didn't actually want the font or formatting. What I really want is for the whole text to use the default font I specified for new notes. The reasonable thing would be hit Undo to return to an empty note, and do a Paste and Match Style. But if I do that I won't get my default font. Rather, the whole text will use a font from the original rich text. So it seems Undo doesn't return me 100% to the state the text view was in previously. My workaround is to discard that note, create a new note, and this time remember to do Paste and Match Style.
--Andy
On May 18, 2016, at 11:47 PM, Rick Mann <email@hidden> wrote:
>
> I seem to be unable to set the font used in an NSTextView that uses bindings to set the text content. The property it's bound to creates a plain NSString (no attributes).
>
> I've tried setting the font, setting the typing attributes, setting the font on textStorage, all to no avail.
>
> Any ideas? Thanks.
>
> --
> Rick Mann
> email@hidden
>
>
>
> _______________________________________________
>
> 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
_______________________________________________
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