Here's how to do it. Even reading the documentation, it's very unclear.
First, you have to get the characteristics of a font, which will give you the constants to use in your UIFontDescriptorFeatureSettingsAttribute
. I got mine from this post.
This gives you feature type identifier keys, and your options for their values, the feature selector identifier keys.
NSArray *timerDisplaySettings = @[
@{ UIFontFeatureTypeIdentifierKey: @(6),
UIFontFeatureSelectorIdentifierKey: @(1)
},
@{ UIFontFeatureTypeIdentifierKey: @(17),
UIFontFeatureSelectorIdentifierKey: @(1)
}];
then you create a font descriptor by adding to a descriptor - this way you can specify the font name and family via UIFont
:
UIFont *font = [UIFont fontWithName:@"HelveticaNeue-UltraLight" size:32];
UIFontDescriptor *originalDescriptor = [font fontDescriptor];
UIFontDescriptor *timerDescriptor =[originalDescriptor fontDescriptorByAddingAttributes: @{ UIFontDescriptorFeatureSettingsAttribute: timerDisplaySettings }];
Then, close the loop and create the font with your descriptor. (The size "0.0" simply means we aren't scaling it from its original size of 32.
UIFont *timerFont = [UIFont fontWithDescriptor: timerDescriptor size:0.0];