Use medieval (lowercase, unlined) numbers

I have a request from a client to use a specific font in an iOS 7 project because it has medieval numbers .

Is there a way to activate these numbers for NSAttributedString? Because the default pad numbers are used, which are included in the font as well.


Here is an example. Both lines have the same font without a variant (Regular), once with activated numbers from the Middle Ages, the second with default numbers.

enter image description here

+8
objective-c cocoa-touch ios7 nsattributedstring typography
source share
2 answers

They are called lowercase numbers and can be included using the UIFontDescriptor .

First you need to import CoreText for some constants:

 #import <CoreText/SFNTLayoutTypes.h> or @import CoreText.SFNTLayoutTypes; 

Then create the font using the font descriptor. Here I use the Georgian family:

 NSDictionary *lowercaseNumbers = @{ UIFontFeatureTypeIdentifierKey: @(kNumberCaseType), UIFontFeatureSelectorIdentifierKey: @(kLowerCaseNumbersSelector), }; UIFontDescriptor *descriptor = [[UIFontDescriptor alloc] initWithFontAttributes: @{ UIFontDescriptorFamilyAttribute: @"Georgia", UIFontDescriptorFeatureSettingsAttribute:@[ lowercaseNumbers ], }]; UIFont *font = [UIFont fontWithDescriptor:descriptor size:15]; 

Result:
enter image description here

Edit: As @ Random832 noted, in Georgia there are only lowercase numbers, so the result does not matter. However, @vikingosegundo confirmed that this code works on supported fonts. Thanks.

enter image description here

The top row was generated using

 UIFont *font = [UIFont fontWithName:@"DIN Next LT Pro" size:12]; if (font) label.font = font; 

second line with

 NSDictionary *lowercaseNumbers = @{ UIFontFeatureTypeIdentifierKey:@(kNumberCaseType), UIFontFeatureSelectorIdentifierKey: @(kLowerCaseNumbersSelector)}; UIFontDescriptor *descriptor = [[UIFontDescriptor alloc] initWithFontAttributes: @{UIFontDescriptorFamilyAttribute: @"DIN Next LT Pro",UIFontDescriptorFeatureSettingsAttribute:@[ lowercaseNumbers ]}]; UIFont *font = [UIFont fontWithDescriptor:descriptor size:12]; if (font) label.font = font; 
+11
source share

Another question has a pointer in the right direction, although the question refers to tabular figures [proportionally] rather than text vs lining.

It looks like you can use CTFontDescriptorCreateCopyWithFeature with kNumberCaseType set to kLowerCaseNumbersSelector to display numbers this way.

Here's another related question , and here's the blog post provided in the answer .

+2
source share

All Articles