【发布时间】: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