ios swift 纯代码添加UIBarButtonItem

萧和同
2023-12-01

示例1

    let item = UIBarButtonItem(title: "Save", style: .plain, target: self, action: #selector(rightBarBtnItemClick));
    self.navigationItem.rightBarButtonItem=item

示例2

        let item1 = UIBarButtonItem(image: UIImage(named: "加"), style: .plain, target: self, action: #selector(rightBarBtnItemClick))        
        self.navigationItem.rightBarButtonItem = item1
    @objc func rightBarBtnItemClick(){
        print("被点了")
    }
 类似资料: