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?
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With