Can I change the position of navigationbar item?

前端 未结 7 914
无人共我
无人共我 2021-01-31 18:57

Here is the snapshot: \"enter

And the code is here:

UIButton *leftButton =         


        
7条回答
  •  南笙
    南笙 (楼主)
    2021-01-31 19:50

    Here's a Swift 3 version of the most voted answer:

     let soundButton = UIBarButtonItem(image:image , style: UIBarButtonItemStyle.plain, target: self, action: #selector(self.soundPressed))
    
            let negativeSpacer = UIBarButtonItem(barButtonSystemItem: .fixedSpace, target: nil, action: nil)
            negativeSpacer.width = -5
    
            self.navigationItem.rightBarButtonItems = [negativeSpacer,soundButton]
    

提交回复
热议问题