简体   繁体   English

在iOS Xamarin中设置后退按钮标题文本

[英]set back button title text in iOS Xamarin

I want to set the BackButton Title text to ""(means empty). 我想将BackButton标题文本设置为“”(表示为空)。 I am using below code to set the Title but it is not working. 我正在使用下面的代码来设置标题,但是它不起作用。

Try 1 : 尝试1:

this.NavigationItem.BackBarButtonItem = new UIBarButtonItem("", UIBarButtonItemStyle.Plain, null);

Try 2 : 试试2:

this.NavigationItem.BackBarButtonItem.Title = "";

it is give the object is not set to instance . 它是给object is not set to instanceobject is not set to instance

Is there any way to set the Back button title null in iOS. 有没有办法在iOS中将“后退”按钮标题设置为null。

Any Help Will be Appreciated. 任何帮助将不胜感激。

Back Title depends on Title property of ViewController . 后退标题取决于ViewController的Title属性。

and it could be set as below , here vc is the instance of controller which is pushed inside UINavigationController . 它可以如下设置,这里vc是在UINavigationController内部推送的控制器的实例。

vc.NavigationItem.SetLeftBarButtonItem (new UIBarButtonItem(
UIImage.FromFile("29_icon.png"), UIBarButtonItemStyle.Plain, (sender, args) => {
    NavigationController.PopViewControllerAnimated(true);
}), true);

https://developer.xamarin.com/recipes/ios/content_controls/navigation_controller/change_the_back_button/ https://developer.xamarin.com/recipes/ios/content_controls/navigation_controller/change_the_back_button/

Above link explains in details . 上面的链接详细说明。 Let me know after this also if you find problem doing it . 如果您在执行此操作时遇到问题,也请在此之后通知我。

For the workaround I do simple trick. 对于变通办法,我做一些简单的技巧。

before going to new UIViewController set the Title to "" . 在转到新的UIViewController之前,将Title设置为"" and on Back button press when you come to ViewController inside the ViewDidAppear method set the Title again. 然后,当您进入ViewDidAppear方法内的ViewController时,请按Back按钮,再次设置Title。

Back button by default use title from previous view controller. “后退”按钮默认使用上一个视图控制器中的标题。 So you need to change title of previous of veiw controller to change back button title. 因此,您需要更改veiw控制器的前一个标题才能更改后退按钮标题。

To hide title, you can use SetBackButtonTitlePositionAdjustment to set offset of Title and move title to invisible area of button by passing (-80,-80) in offset. 若要隐藏标题,可以使用SetBackButtonTitlePositionAdjustment设置Title的偏移量,并通过在偏移量中传递(-80,-80)将标题移动到按钮的不可见区域。

Try this 尝试这个

this.NavigationItem.SetLeftBarButtonItem(new UIBarButtonItem("text", UIBarButtonItemStyle.Plain , (sender, args) => { }), true); this.NavigationItem.SetLeftBarButtonItem(new UIBarButtonItem(“ text”,UIBarButtonItemStyle.Plain((sender,args)=> {}),true);

You can set it like this in the parent controller before doing PushViewController 您可以在执行PushViewController之前在父控制器中像这样设置

this.NavigationItem.BackBarButtonItem = new UIBarButtonItem("", UIBarButtonItemStyle.Plain, null); this.NavigationItem.BackBarButtonItem = new UIBarButtonItem(“”,UIBarButtonItemStyle.Plain,null);

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

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