要在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中添加按钮。您可以根据需要自定义按钮的外观和功能。