无法在 UITabBarItem 上启用字母间距(字距调整) [英] Unable to enable letter spacing (kerning) on UITabBarItem

查看:78
本文介绍了无法在 UITabBarItem 上启用字母间距(字距调整)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 UITabBarItem 标题标签上启用文本字距调整(增加字母间距).但是为 UITabBarItem 提供 NSKernAttributeName 属性没有任何区别.然而,其他两个属性正在起作用:NSForegroundColorAttributeName、NSFontAttributeName.我已经尝试过系统字体和另一种字体:SFUIDisplay-Regular.

I am trying to enable Text Kerning (increase Letter spacing) on UITabBarItem title labels. But providing the NSKernAttributeName attribute for the UITabBarItem does not make any difference. The other two attributes, however, are working: NSForegroundColorAttributeName, NSFontAttributeName. I have tried both with the system font face, and another font face: SFUIDisplay-Regular.

是的,我也尝试使用 UIControlStateNormal 和 UIControlStateSelected.

And YES, i also tried using UIControlStateNormal and UIControlStateSelected.

代码如下:

for (UITabBarItem *item in self.tabBar.items)
{
[item setTitleTextAttributes: @{
                    NSKernAttributeName: @(4.0f), /* does nothing */
                    NSForegroundColorAttributeName: [AppStyle whiteColor],
                    NSFontAttributeName: font
                }
                forState:UIControlStateNormal];

NSKernAttributeName 属性没有任何效果.

the NSKernAttributeName attribute doesn't have any effect.

我也试过在 Appearance 中这样做,当应用程序加载时,像这样:

I have also tried doing it in Appearance, when the application loads, like this:

    NSDictionary *attributes = @{
                             NSKernAttributeName: @(4.0f) /* does nothing */
                             };
[[UITabBarItem appearance] setTitleTextAttributes: attributes
                                         forState: UIControlStateNormal];
[[UITabBarItem appearance] setTitleTextAttributes: attributes
                                         forState: UIControlStateSelected];

同样什么都不做.

我能够让 NSKernAttributeName 工作的唯一地方是在 UILabel 上使用 setAttributedText 时.

The only place i was able to get NSKernAttributeName working, is when using setAttributedText on a UILabel.

你们知道为什么设置其他标题文本属性对 UITabBarItem 有效,而 NSKernAttributeName 不行吗?

Do you guys know why setting the other title text attributes works on UITabBarItem, but NSKernAttributeName does not?

推荐答案

它对我也没有任何改变.Apple 文档检查上面的链接.只能自定义四个键:

It did not change anything for me as well. Apple Documentation checked on above link. Only four keys can be customized :

NSString *const UITextAttributeFont; 
NSString *const UITextAttributeTextColor; 
NSString *const UITextAttributeTextShadowColor; 
NSString *const UITextAttributeTextShadowOffset; 

这篇关于无法在 UITabBarItem 上启用字母间距(字距调整)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆