navigation bar right bar button items spacing

前端 未结 10 2075
执念已碎
执念已碎 2021-01-31 16:47

I have created a with left bar button item added from storyboard, titleView and three right bar button items from code.

Here is the code:

override func         


        
10条回答
  •  一整个雨季
    2021-01-31 17:31

    let rightActionButton:UIButton = UIButton()
    
    if #available(iOS 11.0, *) {
    
        let widthConstraint = rightActionButton.widthAnchor.constraint(equalToConstant: 30)
        let heightConstraint = rightActionButton.heightAnchor.constraint(equalToConstant: 30)
        heightConstraint.isActive = true
        widthConstraint.isActive = true
    }
    else {
        rightActionButton.frame = CGRect.init(x: 0, y: 0, width: 30, height: 30)
    }
    
    rightActionButton.setImage(UIImage.init(named: "3-dots-right-button"), for: .normal)
    rightActionButton.addTarget(self, action: #selector(handleRightMenu), for: UIControlEvents.touchUpInside)
    rightActionButton.setTitle("", for: .normal)
    rightActionButton.tintColor = UIColor(hex:K.NODD_GREEN_HEX)
    
    
    let rightActionBarButton:UIBarButtonItem = UIBarButtonItem(customView: rightActionButton)
    
    let rightBarButtonItem1 = rightActionBarButton
    let rightBarButtonItem2 = UIBarButtonItem(barButtonSystemItem: .action, target: self, action: #selector(handleRight2Menu))
    
    self.navigationItem.rightBarButtonItems = [rightBarButtonItem1,rightBarButtonItem2]
    

提交回复
热议问题