Error when instantiating a UIFont in an text attributes dictionary

后端 未结 4 947
北恋
北恋 2020-12-11 01:58

I\'m trying to set the font of the UIBarButtonItem like so:

let barButton = UIBarButtonItem.appearance()
barButton.setTitleTextAttributes([NSFon         


        
4条回答
  •  既然无缘
    2020-12-11 02:16

    Setting Custom font is little bit tricky, since they don't have font and title properties. Hope this following answer will help you.

    let font = UIFont(name: "", size: )
    var leftBarButtonItem = UIBarButtonItem(title: "", style: UIBarButtonStyle.Plain, target: self, action: "buttonClicked:")
    leftBarButtonItem.setTitleTextAttributes([NSFontAttributeName:font!], forState: UIControlState.Normal)
    self.navigationItem.leftBarButtonItem = leftBarButtonItem
    

提交回复
热议问题