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

标签 ios uibutton uilabel kerning

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

相关文章:

iphone - 关于 UILabel 和 UIImageView 放置处理的一些问题?

ios - 如何获取用户 didSelectRowAtIndexPath 的次数?

objective-c - 在 UITableview 中加载数据问题

ios - 以编程方式将 UIButton 添加到 rootview,我做错了什么?

ios - 条件检查帮助 xcode

iphone - UISegmentedControl 委托(delegate)/触摸事件

ios - 在 CNContactViewController 中预加载/显示数据(swift)

javascript - 在最新的 iOS 更新到 12.2 后,如何修复 iOS 主屏幕 Chrome 快捷方式中的 "whatsapp://"协议(protocol)点击中断?

iphone - 无法设置 UIButton 的标题

ios - 将背景色设置为RGB UIColor ButtonTypeRoundedRect