Re: NSTextField in many colours
Re: NSTextField in many colours
- Subject: Re: NSTextField in many colours
- From: "Gerriet M. Denkmann" <email@hidden>
- Date: Sun, 24 Sep 2006 10:22:12 +0200
On 23 Sep 2006, at 22:20, Matt Neuburg wrote:
On Sat, 23 Sep 2006 18:44:18 +0200, "Gerriet M. Denkmann"
<email@hidden> said:
I have an NSTextField where I do:
[ textField setAttributedStringValue: stringInManyColours ];
Works ok.
1. When I select something in this NSTextField, the text turns to
black. Not really a problem.
No? I'd sure object to that if it happened to me.
But:
2. From now on the text remains all black, even if it is set again
with the stringInManyColours.
This is not acceptable.
So:
What am I doing wrong?
Perhaps you have neglected to call
setAllowsEditingTextAttributes:YES? m.
Well, not so much neglected, but just not known about.
But even now that I read the documentation in NSTextView, I would
decide NOT to use it.
The documentation says about "flag":
"If YES, the user is permitted to change font attributes of the
receiver’s text; if flag is NO, the user isn’t so permitted."
My text-field is selectable, but not editable. So the flag should be
NO. Shouldn't it?
The documentation continuous:
"You can change text attributes programmatically regardless of this
setting."
So, for a text field which is only set programmatically, this flag
clearly does not matter at all.
Well, in the end I decided to follow your advice and ignore the
documentation. Now the coloured string can even be copied and pasted
with all its glorious colours. Thanks a lot!
Only: at the first click the font changes from the one in the nib
file (System Font = Lucida Grande 13) to Helvetica 12.
No big deal, but looks kind of funny.
(The attributed string I am inserting has an attributes dictionary
with only one entry: NSForegroundColorAttributeName; the
documentation says that the default font is Helvetica 12).
This click-induced Helvetica 12 stays till the end of time, unless I
insert the line:
[ [ textField window ] makeFirstResponder: nil ];
before:
[ textField setAttributedStringValue: stringInManyColours ];
Now the font is back to Lucida (until the next click).
(Seems like I have neglected to use fixAttributesInRange on my
stringInManyColours; using this removes the change-font-on-click
feature)
Kind regards,
Gerriet.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden