How to adjust UIToolBar left and right padding

后端 未结 10 550
自闭症患者
自闭症患者 2020-12-02 05:05

I create one UIToolbar with code and another with interface builder. But, found out the two toolbar having different left and right padding which shown below:

From I

10条回答
  •  臣服心动
    2020-12-02 05:34

    I had the same issue, and there's a neat trick you can do with a UIBarButtonSystemItemFixedSpace, add one of these with a negative width before your first button and after your last button and it will move the button to the edge.

    For example, to get rid of the right hand margin add the following FixedSpace bar item as the last item:

    Update for iOS 11 up to 13

    • Swift

      let negativeSeperator = UIBarButtonItem(barButtonSystemItem: .fixedSpace, target: nil, action: nil)
      negativeSeperator.width = 12
      

      Width must be positive in Swift version


    • Objc

      UIBarButtonItem *negativeSeparator = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
      negativeSeparator.width = -12;
      

    The margins on the left and right are 12px.

    Update for iOS7 - margins are 16px on iPhone and 20px on iPad!

提交回复
热议问题