对于iOS 7,Apple制作了Helvetica Thin / Light的特殊修改版本,它具有圆形句点和冒号:
将此与在Xcode中使用Helvetica-Neue Thin或Helvetica-Neue Light进行比较:
是否可以开发具有圆形冒号和句号的特殊修改版本的应用程序?
编辑:原来这些圆形冒号和句号不是由Apple自定义设计的,它们是“字符替换”,您可以在自己喜欢的字体字形查看器中看到它们。
答案 0 :(得分:11)
这是怎么做的。即使阅读文档,也很不清楚。
首先,您必须获得字体的特征,这将为您提供在UIFontDescriptorFeatureSettingsAttribute
中使用的常量。我从this post得到了我的。
这为您提供了功能类型标识符键,以及它们的值选项,即功能选择器标识符键。
NSArray *timerDisplaySettings = @[
@{ UIFontFeatureTypeIdentifierKey: @(6),
UIFontFeatureSelectorIdentifierKey: @(1)
},
@{ UIFontFeatureTypeIdentifierKey: @(17),
UIFontFeatureSelectorIdentifierKey: @(1)
}];
然后通过添加到描述符来创建字体描述符 - 这样您就可以通过UIFont
指定字体名称和族:
UIFont *font = [UIFont fontWithName:@"HelveticaNeue-UltraLight" size:32];
UIFontDescriptor *originalDescriptor = [font fontDescriptor];
UIFontDescriptor *timerDescriptor =[originalDescriptor fontDescriptorByAddingAttributes: @{ UIFontDescriptorFeatureSettingsAttribute: timerDisplaySettings }];
然后,关闭循环并使用描述符创建字体。 (大小“0.0”仅表示我们没有将其从原始大小32缩放。
UIFont *timerFont = [UIFont fontWithDescriptor: timerDescriptor size:0.0];
答案 1 :(得分:4)
为了将来的读者,要看到字体特征数组,在Objective-C中它是:
@import CoreText;
和
- (void)fontFeatures:(UIFont *)font {
NSArray *features = CFBridgingRelease(CTFontCopyFeatures((__bridge CTFontRef)font));
if (features) {
NSLog(@"%@: %@", font.fontName, features);
}
}
对于产生的HelveticaNeue-UltraLight
:
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;
}
);
}
)
因此,在iOS 8中,对于HelveticaNeue-UltraLight
,键17是“Character Alternatives”,值1是“Time Punctuation”。
要在Swift中查看这些功能,它是:
import CoreText
和
func fontFeatures(font: UIFont) {
if let features = CTFontCopyFeatures(font) as NSArray! {
println("\(font.fontName): \(features)")
}
}
答案 2 :(得分:0)
是的,您可以通过iOS 7的新动态类型系统访问这些功能。 http://tirania.org/monomac/archive/2013/Sep-25.html