Can't enable letter markup (kerning) on ​​UITabBarItem

I am trying to enable Text Kerning (increase the spacing between letters) on the UITabBarItem header labels. But providing NSKernAttributeName for the UITabBarItem doesn't make any difference. However, two other attributes are in effect: NSForegroundColorAttributeName, NSFontAttributeName. I've tried with both the system font face and a different font: SFUIDisplay-Regular.

And YES, I also tried using UIControlStateNormal and UIControlStateSelected.

Here is the code:

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

      

The NSKernAttributeName has no effect.

I also tried to do this in Appearance when the app loads, for example:

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

      

Which also does nothing.

The only place I've been able to get NSKernAttributeName to work is when using setAttributedText in UILabel.

Do you guys know why setting other header text attributes works on UITabBarItem, but NSKernAttributeName doesn't?

+4


source to share


1 answer


It didn't change anything for me either. I checked the Apple documentation from the link above. Only four keys can be configured:



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

      

+4


source







All Articles