要在navigationBar中添加按鈕,您可以使用以下方法:
let addButton = UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(addButtonTapped))
navigationItem.rightBarButtonItem = addButton
let customButton = UIButton(type: .custom)
customButton.setTitle("Custom Button", for: .normal)
customButton.addTarget(self, action: #selector(customButtonTapped), for: .touchUpInside)
let customItem = UIBarButtonItem(customView: customButton)
navigationItem.rightBarButtonItem = customItem
let customItem = UIBarButtonItem(title: "Custom Button", style: .plain, target: self, action: #selector(customButtonTapped))
navigationItem.rightBarButtonItem = customItem
無論您選擇哪種方法,都可以在navigationBar中添加按鈕。您可以根據需要自定義按鈕的外觀和功能。