gpt4 book ai didi

ios - 如何在导航栏右侧添加多个 UIBarButtonItems?

转载 作者:IT王子 更新时间:2023-10-29 07:35:54 28 4
gpt4 key购买 nike

我希望在我的 UINavigationBar 右侧有多个 UIBarButtonItem。我怎样才能做到这一点?

我正在尝试的示例如下所示 - 您会注意到右上角有多个按钮。

enter image description here

最佳答案

快速使用它:

override func viewDidLoad() {
super.viewDidLoad()

let editImage = UIImage(named: "plus")!
let searchImage = UIImage(named: "search")!

let editButton = UIBarButtonItem(image: editImage, style: .Plain, target: self, action: "didTapEditButton:")
let searchButton = UIBarButtonItem(image: searchImage, style: .Plain, target: self, action: "didTapSearchButton:")

navigationItem.rightBarButtonItems = [editButton, searchButton]
}

像这样写 Action 函数:

func didTapEditButton(sender: AnyObject){
...
}

func didTapSearchButton(sender: AnyObject){
...
}

swift 4 和 5

    override func viewDidLoad() {
super.viewDidLoad()
let editImage = UIImage(named: "edit")!
let searchImage = UIImage(named: "search")!

let editButton = UIBarButtonItem(image: editImage, style: .plain, target: self, action: #selector(didTapEditButton(sender:)))
let searchButton = UIBarButtonItem(image: searchImage, style: .plain, target: self, action: #selector(didTapSearchButton(sender:)))

navigationItem.rightBarButtonItems = [editButton, searchButton]
}

@objc func didTapEditButton(sender: AnyObject){

}

@objc func didTapSearchButton(sender: AnyObject){

}

关于ios - 如何在导航栏右侧添加多个 UIBarButtonItems?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30341263/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com