簡體   English   中英

iOS 11 NavigationBar自定義后退按鈕問題

[英]iOS 11 NavigationBar Custom Back button issue

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

它顯示在下面的輸出中:

在此處輸入圖片說明

在此輸出中,按鈕圖像處於拉伸狀態,並且顯示的尺寸更大。

我期望的是我的按鈕圖像左側沒有拉伸。

任何幫助將不勝感激。

在此輸出中,按鈕圖像處於拉伸狀態,並且顯示的尺寸更大。

原因 :圖像尺寸(寬*高)大於按鈕尺寸。 您可以檢查應用程序文件夾中的圖像文件,該文件應大於27 * 20。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM