我可以在 ios 中对 UILable 和 UIButton 的自定义字体进行字距调整吗?
下面的方法不起作用。字距调整适用于系统字体,但不适用于自定义字体。有人可以帮忙解决问题吗?
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];
最佳答案
你可以试试这个。这可能会有所帮助。
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
我希望这有帮助。
关于ios:自定义字体的字距调整,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32004205/