Monospaced text iOS 9

I have a date countdown in my application in which I would like to use the function of the fixed-width number in San Francisco. I am currently extracting a font using this code:

UIFontDescriptor *countdownFontDescriptor = [UIFontDescriptor preferredFontDescriptorWithTextStyle:UIFontTextStyleBody];
NSArray *additionalFontSettings = @[@{UIFontFeatureTypeIdentifierKey: @(kNumberSpacingType), UIFontFeatureSelectorIdentifierKey: @(kMonospacedNumbersSelector)},
                                    @{UIFontFeatureTypeIdentifierKey: @(kTextSpacingType), UIFontFeatureSelectorIdentifierKey: @(kMonospacedTextSelector)}];
countdownFontDescriptor = [countdownFontDescriptor fontDescriptorByAddingAttributes: @{UIFontDescriptorFeatureSettingsAttribute: additionalFontSettings}];
UIFont *desiredFont = [UIFont fontWithDescriptor:countdownFontDescriptor size:14];

I get monospace numbers as they should appear, but I have semicolons in my line that separate the numbers. Sometimes I see how this character moves. How can I also get the semicolon width? (That's why I tried to add kTextSpacingType)

+4
source share
1 answer

Not sure, but you tried looking (like on Xcode 9.1 beta)

/Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/CoreText.framework/Headers/SFNTLayoutTypes.h.

I see no way to do this there, but maybe someone else can.

0
source

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


All Articles