如何在swift中更改UIBarButtonItem标题大小

时间:2014-10-21 14:09:18

标签: ios swift

我想更改UIBarButtonItem.title大小,我在下面使用了两个不同的代码行:

let font = UIFont(name:"Arial", size: 8)        
     newBarButtonItem.setTitleTextAttributes([NSFontAttributeName:font],forState: UIControlState.Normal)


 newBarButtonItem.setTitleTextAttributes([NSFontAttributeName:UIFont(name:"Arial", size: 8)],forState: UIControlState.Normal)  

当我运行应用程序时,按钮标题不会改变。任何人都可以帮我这个。感谢

2 个答案:

答案 0 :(得分:3)

试试这个

if let font = UIFont(name: "Helvetica", size: 13) {
            barBtn.setTitleTextAttributes([NSFontAttributeName: font], forState: UIControlState.Normal)
        }

答案 1 :(得分:1)

您也可以在全球范围内执行此操作:

if let font = UIFont(name: "Helvetica", size: 10) {
                UIBarButtonItem.appearance().setTitleTextAttributes([NSFontAttributeName : font], forState: .Normal)
            }