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 {
let fontNormal = UIFont.systemFontOfSize(12)
let fontSelected = UIFont.systemFontOfSize(14, weight: UIFontWeightBold)
override func awakeFromNib() {
self.setTitleTextAttributes([NSFontAttributeName: fontNormal, NSForegroundColorAttributeName: UIColor.grayColor()], forState: UIControlState.Normal)
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