Hide back button text in Xamarin

Viewed 1844

I want to hide text of back button in Xamarin on iOS, I've tried:

<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:

[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

1 Answers

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

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;
  }
Related