The above solutions eliminate the question of the inserted text, but I think the questionnaire probably wanted more. At least I did when I came here.
I just want all the characters in my text box to always have the same font , regardless of whether they are inserted programmatically, from anywhere, inserted, dragged, entered or deleted in Santa Claus. I searched for qaru for this broader issue, but did not find any questions (or answers).
Instead of the solutions given here, use this idea . In detail, give the text box a delegate that implements this ...
- (void)textViewDidChangeSelection:(NSNotification *)note { NSTextView* textView = [note object] ; [textView setFont:[self fontIWant]] ; }
Done. This works in all cases that I could come up with for testing. It's a little strange to watch a change of choice for this. It seems like observing the string value of a text object of a view or registering for NSTextDidChangeNotification would be more logical, but since I already had a delegate set up and since the above was checked and thumbs-up by Nick Zitzmann, I went with it.
Jerry Krinock
source share