我这里有一个巴布托石:

  let doneBarButtonItem: UIBarButtonItem? = {
    let barButtonItem = UIBarButtonItem()
    barButtonItem.setTitleTextAttributes([
        NSAttributedString.Key.font : UIFont(name: "Avenir-Heavy", size: 12)!,
        NSAttributedString.Key.foregroundColor : UIColor.black,
        ], for: .normal)
    barButtonItem.title = "DONE"
    return barButtonItem
}()

但当我按下它时,它会变成另一种字体。突出显示时更改字体的属性是什么?谢谢您。

最佳答案

barButtonItem.setTitleTextAttributes([
        NSAttributedString.Key.font : UIFont(name: "Avenir-Heavy", size: 12)!,
        NSAttributedString.Key.foregroundColor : UIColor.black,
        ], for: .highlighted) // This line

关于ios - 突出显示swift 4.2时barButtonItem的字体更改,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/55146685/

10-10 21:09