How to adjust space between two UIBarButtonItem in rightBarButtonItems

前端 未结 14 2080
悲&欢浪女
悲&欢浪女 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:34

    Might be a bit late for this answer however this can help the newest IOS+Swift combination (IOS 10 and Swift 3 in my case). Here I describe a general approach for how to move items right/left for rightBarButtonItems/leftBarButtonItems:

    The property you we have use here to move a barButtonItem is "imageEdgeInsets" . So, Here how to use this property -

    yourBarButtonItem.imageEdgeInsets = UIEdgeInsetsMake(top, left, bottom, right)

    These top, left, bottom, right are of type CGFloat and these are basically margin value that pushes your item from/to each other. For decreasing a space, we can just use minus (-) values like this " -10 ".

    So, for example if we want to use this for a group of leftBatButtonItems and say, if we want to move a item to the a bit right, then we can do this -

    ourBarButtonItem.imageEdgeInsets = UIEdgeInsetsMake(0.0, 0.0, 0.0, -15)
    

    I hope we get the general idea here and hope it helps :)

提交回复
热议问题