Ironman Ironman -4 years ago 144
iOS Question

How to set LeftBarButton at the place of BackButton in ios

I have set LeftBarButton in the NavigationItem is below way.

Code :

UIButton leftBtn = new UIButton();
leftBtn.Frame = new CoreGraphics.CGRect(0, 14, 30, 30);
leftBtn.SetImage(UIImage.FromBundle("cancel_white_icon"), UIControlState.Normal);
leftBtn.TintColor = GargiColor.WhiteColor();

UIBarButtonItem barBtnLeft = new UIBarButtonItem();
barBtnLeft.CustomView = leftBtn;
barBtnLeft.TintColor = GargiColor.WhiteColor();
NavigationItem.SetLeftBarButtonItem(barBtnLeft, true);


Output :
enter image description here

EDIT :

After adding @SushiHangover code the Output is belowenter image description here

What I am Expected :

The Cancel Button have more space in the Left Side. How to set it to LeftSide as the backbutton.

My Require Output is below :

enter image description here

@SushiHangover final output :enter image description here

Answer Source
var negativeSpace = new UIBarButtonItem (UIBarButtonSystemItem.FixedSpace);
negativeSpacae.Width = -8;

var leftBtn = new UIButton (new RectangleF (0, 0, 25, 25));
leftBtn.SetImage(UIImage.FromBundle("cancel_white_icon"), UIControlState.Normal);
leftBtn.TintColor = GargiColor.WhiteColor();

UIBarButtonItem [] bArray = {
    negativeSpace, new UIBarButtonItem (leftBtn)
};
NavigationItem.SetLeftBarButtonItems (bArray, true);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download