Remove space between buttons in rightbuttonitems navigation element

I use self.navigationItem.rightBarButtonItems to customize the navigation bar items. However, for the panel buttons, I use a custom view (button). I observe that there is a distance between the buttons. How can i remove this?

+4
source share
4 answers

You cannot delete it. You can get around this by creating a panel element with a custom view in which the custom view has custom buttons that are all added as subzones. This way you can directly control the exact positioning.

+2
source

I know it too late, but I solved it using the following UIBarButtonItem method use

 [barbuttonitem setImageInsets:UIEdgeInsetsMake(0, -30, 0, -70)]; 
+13
source

I solved this using the storybord interface. I know that you are using a custom panel, but this answer will be useful to those using stroybord.

1.Select Bar item .

2. Select Size Inspector .

Here you can find the Inset image using top , bottom AND left , right you can change the position of the panel element.

+4
source

Here is an example of how you can solve this problem:

Create the UIBarButton Extension

 extension UIBarButtonItem { /** Create custom right bar button for reduce space between right bar buttons */ func initRightButton(let imageNamed:String, let target:UIViewController, let selector:Selector) -> UIBarButtonItem { let frame = CGRectMake(0, 0, 30, 30) //Create imageView let imageView = UIImageView(frame:frame) imageView.image = UIImage(named: imageNamed) //Create Button let button = UIButton(frame: frame) button.addTarget(target, action: selector, forControlEvents: .TouchUpInside) //Create View and add imageView and Button let view = UIView(frame: frame) view.addSubview(imageView) view.addSubview(button) return UIBarButtonItem(customView: view) } } 

In your class controller, use the customizeNavigationBar method

 func customizeNavigationBar() { //Create custom right bar button chat for reduce space between right bar buttons let barButton1 = UIBarButtonItem().initRightButton("customImageNamed1", target: self, selector: customSelector) let barButton2 = UIBarButtonItem().initRightButton("customImageNamed2", target: self, selector: customSelector) self.navigationItem.rightBarButtonItems = [barButton1,barButton2] } 
+1
source

Source: https://habr.com/ru/post/1489769/


All Articles