我在更改已添加到导航 Controller 的 BarButtonItem 的 swift Xcode 项目中的字体时遇到问题。我能够毫无问题地更改按钮的颜色,但字体不会改变。代码:
var navTextColor = UIColor(red:0.3, green:0.09, blue:0.05, alpha:1.0)
self.navigationController?.navigationBar.tintColor = navTextColor
最佳答案
如果您创建并链接到 UIBarButtonItem
的 socket (例如 @IBOutlet var barButton: UIBarButtonItem!
),您应该能够使用 更改字体类型>setTitleTextAttributes
在 socket 上。
barButton.setTitleTextAttributes([ NSFontAttributeName: UIFont(name: "Arial", size: 12)!], forState: UIControlState.Normal)
Swift3
barButton.setTitleTextAttributes([ NSFontAttributeName: UIFont(name: "Arial", size: 12)!], for: UIControlState.normal)
关于xcode - 使用 Swift (Xcode 6) 更改 BarButtonItem 字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27570826/