突出显示swift 4.2时barButtonItem的字体更改

时间:2019-03-13 16:22:14

标签: ios swift uibarbuttonitem

我在这里有一个barbuttonItem:

  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
}()

但是,当我按它时,它会更改为其他字体。突出显示时更改字体的属性是什么?谢谢。

1 个答案:

答案 0 :(得分:1)

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