【问题标题】:How to change UIBarButtonItem title size in swift [duplicate]如何快速更改 UIBarButtonItem 标题大小 [重复]
【发布时间】:2014-10-21 14:09:18
【问题描述】:

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

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)  

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

【问题讨论】:

标签: ios swift


【解决方案1】:

试试这个

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

【讨论】:

    【解决方案2】:

    您也可以全局执行:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多