如何在ios中的BackButton位置设置LeftBarButton

时间:2017-05-19 12:08:29

标签: ios xamarin xamarin.ios back-button uinavigationitem

我已经在NavigationItem中设置了LeftBarButton。

代码:

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);

输出 enter image description here

编辑:

添加 @SushiHangover 代码后,输出低于enter image description here

我的期望:

“取消”按钮在左侧有更多空间。如何将其设置为LeftSide作为后退按钮。

我的要求输出如下:

enter image description here

@SushiHangover最终输出:enter image description here

1 个答案:

答案 0 :(得分:1)

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);