Change BarButtonItem Font Using Swift (Xcode 6)

I had a problem changing the font in my Quick Xcode project of the BarButtonItem element that was added to the navigation controller. I was able to change the color of the button without any problems, but the font will not change. Code:

var navTextColor = UIColor(red:0.3, green:0.09, blue:0.05, alpha:1.0) self.navigationController?.navigationBar.tintColor = navTextColor 
+6
source share
2 answers

If you create and disable (e.g. @IBOutlet var barButton: UIBarButtonItem! ) UIBarButtonItem with your UIBarButtonItem , you can change your font type using setTitleTextAttributes in the output.

 barButton.setTitleTextAttributes([ NSFontAttributeName: UIFont(name: "Arial", size: 12)!], forState: UIControlState.Normal) 

Swift3

 barButton.setTitleTextAttributes([ NSFontAttributeName: UIFont(name: "Arial", size: 12)!], for: UIControlState.normal) 
+15
source

Swift 3

Another easy way to change the TabBarItem font is to use this code in ViewDidLoad() from the UITabBarController : (No need to create an Outlet)

 UITabBarItem.appearance().setTitleTextAttributes([NSFontAttributeName: UIFont(name: "IranSansMobile", size: 15)!], for: UIControlState.normal) 
0
source

Source: https://habr.com/ru/post/979940/


All Articles