7

[[NSFontManager sharedFontManager] addFontTrait:(nullable id)sender]自分のコードだけを使用するのと同じことを達成したい

ドキュメントの状態

This action method causes the receiver to send its action 
message up the responder chain.
By default, the action message is changeFont:.
When a responder replies by providing a font to convert in
a convertFont: message, the receiver converts the font by 
adding the trait specified by sender. This trait is determined 
by sending a tag message to sender and interpreting it as a font 
trait mask for a convertFont:toHaveTrait: message.

だから私は試しました

NSFontManager * fm = [NSFontManager sharedFontManager];
NSFont * font = [fm selectedFont];
NSFont * modifiedFont = [fm convertFont:font toHaveTrait:NSFontItalicTrait];
[fm setSelectedFont:modifiedFont isMultiple:YES];
[NSApp sendAction:@selector(changeFont:) to:fm.target from:fm];

また

[[self.window firstResponder] tryToPerform:@selector(changeFont:) with:modifiedFont];

しかし、明らかに私はいくつかの点を見逃しています

NSFontManager の実際の実装は NSTextField のフォントをどのように変更し、これをどのように再現できますか

4

1 に答える 1