How NSFontManager addFontTrait changes the actual font in the user interface element

I want to achieve the same as [[NSFontManager sharedFontManager] addFontTrait:(nullable id)sender] using only my code

Document Status

 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. 

so i tried

 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]; 

or

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

but it’s clear that I missed some point

How the actual implementation in NSFontManager changes the font to NSTextField and how it can be reproduced

+7
cocoa nstextfield nstextview nsfontmanager
source share

No one has answered this question yet.

See related questions:

1264
How to check active internet connection on iOS or macOS?
1132
Xcode - How to fix "NSUnknownKeyException", reason: ... this class does not match the key value encoding the error "X"?
661
How to create delegates in Objective-C?
548
What does the NS prefix mean?
4
Change font, font color and background color of NSTableView at runtime with NSFontPanel?
2
change the color and font of the NStextView
2
Change text color of active and inactive NSTextField
0
NSTextField with spacing between font outline ...
0
How to set selected area state for NSTextView?
0
Cocoa text menu and change fonts in NSOutlineView

All Articles