【问题标题】:Unable to enable letter spacing (kerning) on UITabBarItem无法在 UITabBarItem 上启用字母间距(字距调整)
【发布时间】:2015-07-21 17:19:28
【问题描述】:

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

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

代码如下:

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

NSKernAttributeName 属性没有任何作用。

我也尝试在 Appearance 中执行此操作,当应用程序加载时,如下所示:

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

什么也不做。

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

你们知道为什么设置其他标题文本属性在 UITabBarItem 上有效,但 NSKernAttributeName 无效吗?

【问题讨论】:

  • 您找到问题的答案了吗?
  • 还没有。我现在不得不在 UITabBarItems 上没有字距调整。

标签: objective-c nsattributedstring uitabbaritem kerning letter-spacing


【解决方案1】:

这对我来说也没有任何改变。 Apple Documentation 检查上面的链接。只能自定义四个键:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-25
    • 1970-01-01
    相关资源
    最近更新 更多