如何在 Xcode + Swift 4 中制作自定义 UIBarButtonItem Class?

How to make a custom UIBarButtonItem Class in Xcode + Swift 4?

我正在尝试自定义 UIBarButtonItem class 来更改我添加到视图控制器的条形按钮的字体和颜色。我有 20 多个按钮需要更改。

我如何通过从(Identity Inspector)故事板添加自定义 UIBarButtonItem Class 来做到这一点?

为 UIBarButtonItem 创建 class

class CustomBarButton: UIBarButtonItem {
    override func awakeFromNib() {
        style = .plain
        tintColor = .red

        //Set font name and size
        guard let font = UIFont(name: "Helvetica-Bold", size: 19) else {
            return
        }

        setTitleTextAttributes([NSAttributedStringKey.font:font], for: .normal)
    }
}

Set CustomBarButton class to UIBarButtonItem from Identity Inspector.