我在添加到导航控制器的BarButtonItem的
swift
Xcode项目中更改字体时遇到问题.我能够毫无问题地更改按钮的颜色,但字体不会改变.码:
var navTextColor = UIColor(red:0.3,green:0.09,blue:0.05,alpha:1.0) self.navigationController?.navigationBar.tintColor = navTextColor
如果您创建并插入(例如@IBOutlet var barButton:UIBarButtonItem!)链接到您的UIBarButtonItem,您应该能够通过在插座上使用setTitleTextAttributes来更改您的字体类型.
原文链接:https://www.f2er.com/swift/318987.htmlbarButton.setTitleTextAttributes([ NSFontAttributeName: UIFont(name: "Arial",size: 12)!],forState: UIControlState.Normal)
Swift3
barButton.setTitleTextAttributes([ NSFontAttributeName: UIFont(name: "Arial",for: UIControlState.normal)