Search code examples
c#iosxamarin.iosuinavigationbaruinavigationitem

Excessive Spacing between UIBarButtonItem in UINavigation bar in Xamarin iOS


anyone can help me on fixing excessive navigation bar button padding in Xamarin iOS. I am using default UI navigation bar and adding left bar button as well as right bar button. it looks weird when I'm adding number of right bar button because of the unwanted padding between the UI bar buttons.Manually im not setting any frames for UI bar button items

leftButtons [0] = customButton;
leftButtons [1] = logoButton;
rightButtons [0] = networkButton;
rightButtons[1] = refreshButton;
viewController.updateStatusBar (false,"TITLE",rightButtons,leftButtons);

Any help to reduce this spacing is well-appreciated thanks in advance :)


Solution

  • It worked like a charm with a single line of code:

    navigationBarButtonItem.ImageInsets = new UIEdgeInsets(0,15,0,-15);
    

    Please note, this moves only the image location not the touch area, so it's a fix only if you want to move the image spacing little bit to avoid the unwanted spacing between the navigation bar items. If you are using a UIBarButtonItem without an image with it, It may not be usefull for you