我正在以编程方式添加这样的栏按钮项:
let button = UIButton.init(type: .custom)
button.setImage(UIImage(named: "Bar Chart Filled-50"), for: UIControlState.normal)
button.addTarget(self, action: #selector(self.statButtonPressed), for: UIControlEvents.touchUpInside)
button.frame = CGRect(x: 0, y: 0, width: 40, height: 40)
let barButton = UIBarButtonItem(customView: button)
navItem.rightBarButtonItem = barButton
我希望它在页面的导航栏中垂直居中。我将如何以编程方式执行此类操作。