简体   繁体   English

在Xamarin中隐藏后退按钮文本

[英]Hide back button text in Xamarin

I want to hide text of back button in Xamarin on iOS, I've tried: 我想在iOS的Xamarin中隐藏“后退”按钮的文本,我尝试过:

<Style TargetType="NavigationPage">
<Setter Property="BackButtonTitle" Value="" />
</Style>

and this code: 和此代码:

<Style TargetType="ContentPage">
<Setter Property="NavigationPage.BackButtonTitle" Value="" />
</Style>

But text still appears 但是文字仍然出现

SOLVED: 解决了:

iOS renderer: iOS渲染器:

[assembly: ExportRenderer(typeof(ContentPage), typeof(BackButtonPag))]
[assembly: ExportRenderer(typeof(NavigationPage), typeof(BackButtonNav))]

public class BackButtonPag : PageRenderer
    {
        public override void ViewWillAppear(bool animated)
        {
            base.ViewWillAppear(animated);

            if (NavigationController != null)
                NavigationController.TopViewController.NavigationItem.BackBarButtonItem = new UIBarButtonItem("", UIBarButtonItemStyle.Plain, null);
        }
    }

    public class BackButtonNav : NavigationRenderer
    {
        public override void ViewWillAppear(bool animated)
        {
            base.ViewWillAppear(animated);

            NavigationBar.TopItem.BackBarButtonItem = new UIBarButtonItem("", UIBarButtonItemStyle.Plain, null);
        }
    }

Also add this 也添加这个

NavigationPage.BackButtonTitle = ""

to Main.xaml of your MasterDetailPage 到您的MasterDetailPage的Main.xaml

As here said ,you can you can use an empty string for the Back button title: 这里所说,您可以为“后退”按钮标题使用一个空字符串:

NavigationPage.SetBackButtonTitle(this, "");

Or you can set the title of UIBarButtonItem as clear 或者,您可以将UIBarButtonItem的标题设置为clear

public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
  {
     // . . .
     var attribute = new UITextAttributes();
     attribute.TextColor = UIColor.Clear;
     UIBarButtonItem.Appearance.SetTitleTextAttributes(attribute, UIControlState.Normal);
     UIBarButtonItem.Appearance.SetTitleTextAttributes(attribute, UIControlState.Highlighted);
     //. . .

     return true;
  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM