Removing characters from font

109 views Asked by At

As far as I can tell from this WWDC doc, my code should work, but it doesn't:

NSString *fontName = [@"MaisonNeue-" stringByAppendingString:@"Light"];
UIFont *originalFont = [UIFont fontWithName:fontName size:size];
UIFontDescriptor *originalDescriptor = [originalFont fontDescriptor];

NSMutableCharacterSet *cset = [[originalDescriptor objectForKey:UIFontDescriptorCharacterSetAttribute] mutableCopy];
[cset formIntersectionWithCharacterSet:[[NSCharacterSet decimalDigitCharacterSet] invertedSet]];

NSDictionary *newAttributes = @{UIFontDescriptorCharacterSetAttribute: cset};

UIFontDescriptor *monospaceDescriptor = [originalDescriptor fontDescriptorByAddingAttributes:newAttributes];
UIFont *newFont = [UIFont fontWithDescriptor:monospaceDescriptor size:0.0];

What's wrong? The newly created font still contains the characters I specifically removed:

(lldb) p [cset characterIsMember:'2']
(bool) $0 = false
(lldb) po [(NSCharacterSet *)[(id)monospaceDescriptor objectForKey:UIFontDescriptorCharacterSetAttribute] characterIsMember:'2']
false
(lldb) po [(NSCharacterSet *)[[newFont fontDescriptor] objectForKey:UIFontDescriptorCharacterSetAttribute] characterIsMember:'2']
true
0

There are 0 answers