我正在iOS中渲染数字(针对7及以上版本),通过将它们存储在NSAttributedString中,使用“drawAtPoint:”进行渲染。我正在使用Helvetica Neue字体。
我注意到这样绘制的数字不是等比例的——所有字形的宽度都相同。即使是瘦弱的“1”占用的空间也与“0”相同。
测试证实了这一点:
for(NSInteger i=0; i<10; ++i)
{
NSString *iString = [NSString stringWithFormat: @"%d", i];
const CGSize iSize = [iString sizeWithAttributes: [self attributes]];
NSLog(@"Size of %d is %f", i, iSize.width);
}
在其他地方:
有关IT技术的内容。-(NSDictionary *) attributes
{
static NSDictionary * attributes;
if(!attributes)
{
attributes = @{
NSFontAttributeName: [UIFont systemFontOfSize:11],
NSForegroundColorAttributeName: [UIColor whiteColor]
};
}
return attributes;
}
这些结果字形宽度相同,为6.358点。
有没有一些渲染选项可以打开以启用比例数字字形?是否有另一种字体(最好类似于Helvetica Neue)支持比例数字字形(最好内置)?还有其他的选择吗?
谢谢。
#import <CoreText/CoreText.h>
:这是符号定义的地方。 - Benjohn