xcode - 使用 Swift (Xcode 6) 更改 BarButtonItem 字体

标签 xcode swift fonts navigation uinavigationbar

我在更改已添加到导航 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/

相关文章:

objective-c - 日期计算中的语法错误

ios - Xcode 错误?无法在 Storyboard 中制作具有 "detail right"样式的 UITableViewCell

ios - 向 CoreData 添加新版本

ios - 在当前 vc 之上呈现 vc 后,第二次出现白屏。第一次没收到

ios - 如何在 Xcode 7 beta 4 中调用 SecItemCopyMatching?

ios - 在 Swift 中导入数据的最佳方式?

ios - UIActivityIndi​​cator stopAnimating() 不起作用

ios - Xcode 中的自定义字体不起作用

html - 当放置在 <img> 数据 URI 或 <canvas> 中时,SVG 文件中缺少字体

Eclipse IDE 未使用正确的字体