【问题标题】:How to set LeftBarButton at the place of BackButton in ios如何在ios中的后退按钮位置设置LeftBarButton
【发布时间】:2017-05-19 12:08:28
【问题描述】:

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

输出:

编辑:

添加@SushiHangover代码后输出如下

我的期望:

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

我的要求输出如下:

@SushiHangover 最终输出:

【问题讨论】:

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


    【解决方案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);
    

    【讨论】:

    • (negetive) 没有考虑到我之前已经做过了。
    • 这在我的项目中运行良好。我已经测试过了。你确定你添加的是UIBarButtonSystemItem.FixedSpace吗?
    • 你在哪里定义backButton ??
    • 它甚至无法显示Cancel 按钮。我还添加了此代码button.ImageView.Image = UIImage.FromBundle("cancel_white_icon");,但图像不显示。
    • 出了什么问题?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-03
    • 2017-09-21
    相关资源
    最近更新 更多