2015-08-14 63 views
1

我可以在ios中为UILable和UIButton使用Kerning自定义字体吗?ios:确定自定义字体

下面的方法不起作用。 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

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

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

我希望这有助于。