ios:自定义字体的字距调整

时间:2015-08-14 07:06:24

标签: ios uibutton uilabel kerning

我可以在ios中为UILable和UIButton使用自定义字体进行字距调整吗?

以下方法无效。 Kerning适用于系统字体,但不适用于自定义字体。有人可以帮助解决问题吗?

NSMutableAttributedString *attributedString =
   [[NSMutableAttributedString alloc] initWithString:text attributes:
       @{
          NSFontAttributeName : [UIFont fontWithName:@"BebasNeue Bold" size:25],
          NSForegroundColorAttributeName : [UIColor redColor]
     }];

   [attributedString addAttribute:NSKernAttributeName
       value:[NSNumber numberWithFloat:kerning]
       range:NSMakeRange(0, [text length])];
   [self setAttributedText:attributedString];

1 个答案:

答案 0 :(得分:4)

你可以试试这个。这可能有所帮助。

NSMutableAttributedString *attributedString;
attributedString = [[NSMutableAttributedString alloc] initWithString:@"Please test this text"];
[attributedString addAttribute:NSKernAttributeName value:@5 range:NSMakeRange(10, 5)];
[self.label setAttributedText:attributedString];

要获得更多解决方案,请查看以下链接

How to set kerning in iPhone UILabel

我希望这会有所帮助。

相关问题