OGeek|极客世界-中国程序员成长平台

标题: ios:自定义字体的字距调整 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 11:31
标题: ios:自定义字体的字距调整

我可以在 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];



Best Answer-推荐答案


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

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

更多解决方案请查看以下链接

How to set kerning in iPhone UILabel

我希望这会有所帮助。

关于ios:自定义字体的字距调整,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32004205/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4