public func setCustomButton() {
let btnSearch: UIButton = UIButton(type: .custom)
btnSearch.frame = CGRect(x: 0, y: 0, width: 25.0, height: 25.0)
btnSearch.setImage("Your image", for: .normal)
btnSearch.addTarget(self, action: #selector(yourActionName(_:)), for: .touchUpInside)
et btnBarButtonSearch: UIBarButtonItem = UIBarButtonItem(customView: btnSearch)
navigationItem.rightBarButtonItems = [btnBarButtonSearch]
}
надеюсь, это поможет вам.