Adding buttons to toolbar programmatically in swift

前端 未结 6 1568
天命终不由人
天命终不由人 2021-02-04 03:14

I\'m having a hard time adding a button to the toolbar in swift, below you can see an image of the toolbar that I\'m after, unfortunately even though I have it designed in my St

6条回答
  •  北海茫月
    2021-02-04 03:23

    self.navigationController?.toolbarItems = items
    
    self.navigationController?.setToolbarItems(items, animated: false)
    
    self.navigationController?.toolbar.setItems(items, animated: false)
    

    Try it.

            self.navigationController?.toolbarHidden = false
            var items = [UIBarButtonItem]()
            items.append(
                UIBarButtonItem(barButtonSystemItem: .FlexibleSpace, target: self, action: nil)
            )
            items.append(
                UIBarButtonItem(barButtonSystemItem: .Add, target: self, action: "onClickedToolbeltButton:")
            )
    
            self.navigationController?.toolbar.setItems(items, animated: false)
    

提交回复
热议问题