Search code examples
iosswiftuitabbaritemuitabview

Can i only display text in tab bar item and change the style and position


I add a tab bar in storyboard, and do not want to set an image to the tab bar item, and like the following:

enter image description here

How can I change the font and the position for the title of the bar item in storybord?


Solution

  • First select the tab bar item in storyboard, than in Attributes Inspector set System Item and Title Position to Custom, so you will be able to change the position of the title by setting values to Horizontal and Vertical boxes.

    enter image description here

    Finally, to change the font, in your viewDidLoad(), include:

    UITabBarItem.appearance().setTitleTextAttributes([NSFontAttributeName: UIFont(name: "Avenir-BlackOblique", size:20)!, NSForegroundColorAttributeName: UIColor.blue], for: .normal)
    

    NSFontAttributeName allow you to change the font style and NSForegroundColorAttributeName allow you to change the font color.