要在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中添加按钮。您可以根据需要自定义按钮的外观和功能。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:如何在php页面中添加按钮