iOS 11导航栏自定义后退按钮问题

问题描述 投票:0回答:1

在我以前的应用程序中,我想要使用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;
}

它显示在输出下方:

enter image description here

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

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

任何帮助将不胜感激。

ios xamarin.ios uinavigationbar back-button navigationbar
1个回答
0
投票

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

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

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

© www.soinside.com 2019 - 2024. All rights reserved.