How to adjust space between two UIBarButtonItem in rightBarButtonItems

前端 未结 14 2095
悲&欢浪女
悲&欢浪女 2020-12-08 06:44

I am using the following codes to add two button to self.navigationItem.rightBarButtonItems, and I think in iOS7, the space between two buttons are too wide, is there a way

14条回答
  •  悲&欢浪女
    2020-12-08 07:19

    If you are looking to have 2 buttons on the top right with no space in between them or on the right, this has worked for me.

    let imgLeft = UIImage(named: "buttonLeft")?.imageWithRenderingMode(.AlwaysOriginal)
    let bLeft = UIBarButtonItem(image: imgLeft, style: UIBarButtonItemStyle.Done, target: self, action: "action1:")
    let space = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.FixedSpace, target: nil, action: nil)
    space.width = -16.0
    
    bLeft.imageInsets = UIEdgeInsetsMake(0, 0, 0, -25.0)
    
    
    let imgRight = UIImage(named: "buttonRight")?.imageWithRenderingMode(.AlwaysOriginal)
    let bRight = UIBarButtonItem(image: imgRight, style: UIBarButtonItemStyle.Done, target: self, action: "action2:")
    
    bRight.imageInsets = UIEdgeInsetsMake(0, -25, 0, 0)
    
    
    self.navigationItem.rightBarButtonItems = [space,bLeft,bRight ]
    

提交回复
热议问题