首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何编程设置2 rightNavigationButtons

如何编程设置2 rightNavigationButtons
EN

Stack Overflow用户
提问于 2022-05-28 11:26:21
回答 1查看 19关注 0票数 0

我有一个导航按钮,这是代码:

代码语言:javascript
复制
func barItem() {
    let button = UIButton(type: .custom)
    button.setTitle("Watch AR", for: .normal)
    button.addTarget(self, action: #selector(openAR), for: .touchUpInside)
    button.setTitleColor(.orange, for: .normal)
    button.setTitleColor(.gray, for: .highlighted)
    button.sizeToFit()
    
    self.navigationItem.setRightBarButton(UIBarButtonItem(customView: button), animated: true);
}

然后,我尝试在viewDidLoad方法中再添加一个导航按钮

代码语言:javascript
复制
override func viewDidLoad() {
    super.viewDidLoad()
    self.view.backgroundColor = .white
    self.navigationController?.navigationBar.tintColor = UIColor.orange
    self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Add", style: .plain, target: self, action: #selector(savePicture))
    self.barItem()
}

但它不起作用,为什么?

EN

回答 1

Stack Overflow用户

发布于 2022-05-31 12:22:58

代码语言:javascript
复制
override func viewDidLoad() {
    super.viewDidLoad()        
    let barButton1 = UIBarButtonItem(title: "Button 1", style: .plain, target: self, action: #selector(barButtonItem1))        
    let barButton2 = UIBarButtonItem(title: "Button 2", style: .plain, target: self, action: #selector(barButtonItem2))        
    self.navigationItem.setRightBarButtonItems([barButton1, barButton2], animated: true)        
}
    
@objc func barButtonItem1(){
    
}

@objc func barButtonItem2(){
    
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72415283

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档