8

数値を NSAttributedString に格納し、「drawAtPoint:」でレンダリングすることにより、iOS (7 以降をターゲット) で数値をレンダリングしています。私は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);
}

と、他の場所で:

-(NSDictionary *) attributes
{
  static NSDictionary * attributes;
  if(!attributes)
  {
    attributes = @{
                   NSFontAttributeName: [UIFont systemFontOfSize:11],
                   NSForegroundColorAttributeName: [UIColor whiteColor]
                   };
  }
  return attributes;
}

この結果のグリフはすべて同じ幅の 6.358 ポイントです。

比例桁グリフを有効にするためにオンにできるレンダリングオプションはありますか? プロポーショナル数字グリフをサポートする (理想的には組み込みの) 別のフォント (理想的には Helvetica Neue に似たもの) はありますか? 他に何か?

ありがとうございました。

4

1 に答える 1