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

前端 未结 6 1770
故里飘歌
故里飘歌 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 01:05

    Swift 3.x or above:

    internal var textFieldHandlerToolBar: UIToolbar = {
            let tb = UIToolbar.init(frame: CGRect.init(origin: .zero, size: CGSize.init(width: UIScreen.screenSize().width, height: 44.0)))
            let flexibleButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.flexibleSpace, target: nil, action: nil)
            let doneBarButton = UIBarButtonItem.init(title: "Done", style: UIBarButtonItemStyle.done, target: self, action: #selector(actionDonePickerSelection))
            tb.setItems([flexibleButton, doneBarButton], animated: false)
            return tb
        }()
    

    Output:

提交回复
热议问题