How to change the actively selected font / size / weight of a UITabBarItem text in iOS Swift?

I am trying to change the font, size and weight of UITabBarItem text when it is currently selected. I achieved a color change through UIControlState.Selected, but for some reason the font does not change. I searched 12 hours in all environments, and this seems to be an unsolved mystery! I am to such an extent that I believe that there is an error in Swift or Xcode, because the current functionality is strange!

My current code is:

class CustomUITabBarItem: UITabBarItem {

    // Setting Font Constants Here
    let fontNormal = UIFont.systemFontOfSize(12)
    let fontSelected = UIFont.systemFontOfSize(14, weight: UIFontWeightBold)

    override func awakeFromNib() {

        // Following line sets Normal state attributes and it works fine        
        self.setTitleTextAttributes([NSFontAttributeName: fontNormal, NSForegroundColorAttributeName: UIColor.grayColor()], forState: UIControlState.Normal)

        // Following line should set Selected state attributes but it has unexpected behaviour
        self.setTitleTextAttributes([NSFontAttributeName: fontSelected, NSForegroundColorAttributeName: UIColor.orangeColor()], forState: UIControlState.Selected)

     }
}

The end result is bewildering, since the text of UIControlState.Selected has only a color attribute, but the font type, size and weight do not change. I was looking for a code with a clock, checking out different functionality, and even trying to figure out a round solution, but I'm at my end.

, .Selected , , ( .Normal...), ? , - ?

: iOS9.3.2, Swift 2.2, XCode 7.3.1, OSX El Capitan 10.11.5

+4

All Articles