10.9 replacement for [NSFont systemFontOfSize: weight:]

I would like to implement a replacement method for [NSFont systemFontOfSize:13 weight:NSFontWeightLight]which works on Mac OS 10.9 and 10.10.

I can get the font descriptor on [[NSFont systemFontOfSize:13] fontDescriptor].

However, I could not figure out how to change the weight of the font descriptor and create an NSFont from it.

As explained in WWDC 2015, # 804 : 30:17, we should not take the last name from the system font (as suggested here and here ).

Is it possible to change the font descriptor weight and get a new NSFont from it?

+4
source share
2 answers

I can think of two ways, but it does not give exactly the same semantics as +[NSFont systemFontOfSize:weight:].

- -[NSFontManager convertWeight:ofFont:]. , . , , -[NSFontManager weightOfFont:], , 3 "" (. -convertWeight:ofFont:). , , .

- :

NSFontDescriptor* origDescriptor = origFont.fontDescriptor;
NSFontDescriptor* newDescriptor = [origDescriptor fontDescriptorByAddingAttributes:@{ NSFontTraitsAttribute: @{ NSFontWeightTrait: @(-0.2) } }];
NSFont* newFont = [NSFont fontWithDescriptor:newDescriptor size:origFont.pointSize];

-0.2 . , -1,0 1,0, 0 "". , " ". , , , , .

+2

, , , OS X 10.10. [NSFont systemFontOfSize: weight:] OS X 10.10 . 10.9. , , , .

AppKit WWDC , , 10.10 API. , API , 10.10, API , MAS.

0

Source: https://habr.com/ru/post/1607968/


All Articles