I\'m trying to set the font of the UIBarButtonItem
like so:
let barButton = UIBarButtonItem.appearance()
barButton.setTitleTextAttributes([NSFon
The initializer of UIFont
returns an optional because it may fail due to misspelled font name etc.
You have to unwrap it and check:
if let font = UIFont(name: "AvenirNext", size: 15) {
barButton.setTitleTextAttributes([NSFontAttributeName: font], forState: UIControlState.Normal)
}
UPDATED for Swift 3
if let font = UIFont(name: "AvenirNext", size: 15) {
barButton.setTitleTextAttributes([NSFontAttributeName:font], for: .normal)
}