【问题标题】:iOS 11 NavigationBar Custom Back button issueiOS 11 NavigationBar 自定义后退按钮问题
【发布时间】:2018-02-27 06:58:18
【问题描述】:

现在我想在我之前的应用程序中更新 iOS 11 功能。所以现在我在使用下面的代码时

NavigationItem.SetHidesBackButton(false, false);

var negativeSpacae = new UIBarButtonItem(UIBarButtonSystemItem.FixedSpace);

UIButton button = new UIButton(new RectangleF(0, 0, 30, 30));
button.SetImage(UIImage.FromFile("backbutton"), UIControlState.Normal);
button.TintColor = UIColor.White;
button.BackgroundColor = UIColor.Red;

var widthconstraint = button.WidthAnchor.ConstraintEqualTo(27);
var heightconstraint = button.HeightAnchor.ConstraintEqualTo(20);

widthconstraint.Active = true;
heightconstraint.Active = true;

UIBarButtonItem[] bArray = {
                negativeSpacae, new UIBarButtonItem (button)
                };
NavigationItem.SetLeftBarButtonItems(bArray, true);

button.TouchUpInside += (sender, e) =>
{
   this.NavigationController.PopViewController(true);
};
if (UIDevice.CurrentDevice.CheckSystemVersion(11, 0))
{
   ViewRespectsSystemMinimumLayoutMargins = false;
   View.LayoutMargins = UIEdgeInsets.Zero;
}

它显示在输出下方:

在此输出中,按钮图像被拉伸,并且显示更合适的尺寸。

我期待的是我的按钮图像是左侧没有拉伸。

我们将不胜感激。

【问题讨论】:

    标签: ios xamarin.ios uinavigationbar back-button navigationbar


    【解决方案1】:

    在此输出中,按钮图像被拉伸,并且显示更合适的尺寸。

    原因:图片尺寸(宽*高)大于按钮尺寸。您可以查看应用程序文件夹中的图像文件,它应该大于 27*20。

    解决方案button.ImageView.ContentMode = UIViewContentMode.ScaleAspectFit;

    【讨论】: