How to place UIBarButtonItem on the right side of a UIToolbar?

前端 未结 6 1747
故里飘歌
故里飘歌 2020-12-14 00:39

I have designed a view with a toolbar that appears modally in Interface Builder. I have a UIBarButtonItem that is on the left hand side, which I would like to appear on the

6条回答
  •  一整个雨季
    2020-12-14 00:58

    Swift Code:

    func addDoneButton() -> UIToolbar {
        let toolbar = UIToolbar()
        let flexButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.FlexibleSpace, target: nil, action: nil)
        let doneButton = UIBarButtonItem(title: "Done", style: .Plain, target: self, action: Selector("donePressed"))
        toolbar.setItems([flexButton, doneButton], animated: true)
        toolbar.sizeToFit()
        return toolbar
    }
    

提交回复
热议问题