Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to enable letter spacing (kerning) on UITabBarItem

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.

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 attribute doesn't have any effect.

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];

Which also does nothing.

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

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

like image 828
FranticRock Avatar asked Sep 28 '22 06:09

FranticRock


1 Answers

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; 
like image 168
MPG Avatar answered Nov 15 '22 06:11

MPG