iPhone: Adding Info button as right bar button item in navigation bar in code

前端 未结 4 461
北海茫月
北海茫月 2021-02-04 06:42

Has anyone had any success creating an info button (italic \'i\' in a circle) in code (read: without Interface Builder), and then assigning it as the right bar button item of a

4条回答
  •  南旧
    南旧 (楼主)
    2021-02-04 07:21

    For Swift:

    func addRightNavigationBarInfoButton() {
        let button = UIButton(type: .infoDark)
        button.addTarget(self, action: #selector(self.showInfoScreen), for: .touchUpInside)
        self.navigationItem.rightBarButtonItem = UIBarButtonItem(customView: button)
    }
    
    @objc func showInfoScreen() {
        // info bar button pressed
    }
    

提交回复
热议问题