質問

For iOS 7, Apple made a special modified version of Helvetica Thin/Light that has rounded periods and colons:

enter image description here

Compare this to using Helvetica-Neue Thin or Helvetica-Neue Light in Xcode:

enter image description here

Is it possible to develop apps with the special modified version with the rounded colons and periods?

EDIT: Turns out these round colons and periods are not custom designed by Apple, they are "character alternates" and you can see them in your favorite font glyph viewer.

役に立ちましたか?

解決

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];

他のヒント

For the sake of future readers, to see the font features array, in Objective-C it is:

@import CoreText;

and

- (void)fontFeatures:(UIFont *)font {
    NSArray *features = CFBridgingRelease(CTFontCopyFeatures((__bridge CTFontRef)font));

    if (features) {
        NSLog(@"%@: %@", font.fontName, features);
    }
}

For HelveticaNeue-UltraLight that yields:

HelveticaNeue-UltraLight: (
        {
        CTFeatureTypeIdentifier = 1;
        CTFeatureTypeName = Ligatures;
        CTFeatureTypeNameID = 258;
        CTFeatureTypeSelectors =         (
                        {
                CTFeatureSelectorDefault = 1;
                CTFeatureSelectorIdentifier = 2;
                CTFeatureSelectorName = "Common Ligatures";
                CTFeatureSelectorNameID = 259;
            }
        );
    },
        {
        CTFeatureTypeExclusive = 1;
        CTFeatureTypeIdentifier = 6;
        CTFeatureTypeName = "Number Spacing";
        CTFeatureTypeNameID = 262;
        CTFeatureTypeSelectors =         (
                        {
                CTFeatureSelectorDefault = 1;
                CTFeatureSelectorIdentifier = 0;
                CTFeatureSelectorName = "No Change";
                CTFeatureSelectorNameID = 264;
            },
                        {
                CTFeatureSelectorIdentifier = 1;
                CTFeatureSelectorName = "Proportional Numbers";
                CTFeatureSelectorNameID = 263;
            }
        );
    },
        {
        CTFeatureTypeExclusive = 1;
        CTFeatureTypeIdentifier = 17;
        CTFeatureTypeName = "Character Alternatives";
        CTFeatureTypeNameID = 265;
        CTFeatureTypeSelectors =         (
                        {
                CTFeatureSelectorDefault = 1;
                CTFeatureSelectorIdentifier = 0;
                CTFeatureSelectorName = "No Change";
                CTFeatureSelectorNameID = 264;
            },
                        {
                CTFeatureSelectorIdentifier = 1;
                CTFeatureSelectorName = "Time Punctuation";
                CTFeatureSelectorNameID = 266;
            },
                        {
                CTFeatureSelectorIdentifier = 2;
                CTFeatureSelectorName = "Compass Punctuation";
                CTFeatureSelectorNameID = 267;
            },
                        {
                CTFeatureSelectorIdentifier = 3;
                CTFeatureSelectorName = "Weather Punctuation";
                CTFeatureSelectorNameID = 268;
            },
                        {
                CTFeatureSelectorIdentifier = 4;
                CTFeatureSelectorName = "Round Lowercase Punctuation";
                CTFeatureSelectorNameID = 269;
            }
        );
    }
)

Thus, in iOS 8, for HelveticaNeue-UltraLight, key 17 is "Character Alternatives", and value 1 is "Time Punctuation".


To see these features in Swift, it is:

import CoreText

and

func fontFeatures(font: UIFont) {
    if let features = CTFontCopyFeatures(font) as NSArray! {
        println("\(font.fontName): \(features)")
    }
}

Yes, these features are accessible to you via iOS 7's new Dynamic Type system. http://tirania.org/monomac/archive/2013/Sep-25.html

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top