Change BarButtonItem Font Using Swift (Xcode 6) Change BarButtonItem Font Using Swift (Xcode 6) xcode xcode

Change BarButtonItem Font Using Swift (Xcode 6)


If you create and outlet (e.g. @IBOutlet var barButton: UIBarButtonItem!) linked to your UIBarButtonItem, you should be able to change your font type by using setTitleTextAttributes on the outlet.

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

Swift3

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


Swift 3

Another easy way to change all TabBarItems font is using this code in ViewDidLoad() of UITabBarController : (No need to create an Outlet )

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


Swift 5

barButton.setTitleTextAttributes([ NSAttributedString.Key.font: UIFont(name: "Arial", size: 12)!], for: UIControl.State.normal)