在 iOS Xamarin 中设置后退按钮标题文本
set back button title text in iOS Xamarin
我想将 BackButton 标题文本设置为“”(表示为空)。我正在使用以下代码设置标题,但它不起作用。
尝试 1 :
this.NavigationItem.BackBarButtonItem = new UIBarButtonItem("", UIBarButtonItemStyle.Plain, null);
尝试 2 :
this.NavigationItem.BackBarButtonItem.Title = "";
这是给 object is not set to instance
.
有什么方法可以在 iOS 中将后退按钮标题设置为 null。
我们将不胜感激。
返回标题取决于 ViewController 的标题 属性。
也可以这样设置,这里vc是推入UINavigationController里面的controller实例。
vc.NavigationItem.SetLeftBarButtonItem (new UIBarButtonItem(
UIImage.FromFile("29_icon.png"), UIBarButtonItemStyle.Plain, (sender, args) => {
NavigationController.PopViewControllerAnimated(true);
}), true);
以上link解释的很详细。
如果您发现这样做有问题,请在此之后告诉我。
对于解决方法,我做了一些简单的技巧。
在转到新 UI 之前ViewController 将标题设置为 ""
。并在 ViewDidAppear
方法中到达 ViewController 时按下后退按钮,再次设置标题。
后退按钮默认使用上一个视图控制器的标题。所以你需要改变前一个视图控制器的标题来改变后退按钮的标题。
要隐藏标题,可以使用SetBackButtonTitlePositionAdjustment设置标题的偏移量,并通过在偏移量中传递(-80,-80)将标题移动到按钮的不可见区域。
试试这个
this.NavigationItem.SetLeftBarButtonItem(new UIBarButtonItem("text", UIBarButtonItemStyle.Plain , (sender, args) => { }), true);
在做PushViewController之前可以在parent controller中这样设置
this.NavigationItem.BackBarButtonItem = new UIBarButtonItem("", UIBarButtonItemStyle.Plain, null);
我想将 BackButton 标题文本设置为“”(表示为空)。我正在使用以下代码设置标题,但它不起作用。
尝试 1 :
this.NavigationItem.BackBarButtonItem = new UIBarButtonItem("", UIBarButtonItemStyle.Plain, null);
尝试 2 :
this.NavigationItem.BackBarButtonItem.Title = "";
这是给 object is not set to instance
.
有什么方法可以在 iOS 中将后退按钮标题设置为 null。
我们将不胜感激。
返回标题取决于 ViewController 的标题 属性。
也可以这样设置,这里vc是推入UINavigationController里面的controller实例。
vc.NavigationItem.SetLeftBarButtonItem (new UIBarButtonItem(
UIImage.FromFile("29_icon.png"), UIBarButtonItemStyle.Plain, (sender, args) => {
NavigationController.PopViewControllerAnimated(true);
}), true);
以上link解释的很详细。 如果您发现这样做有问题,请在此之后告诉我。
对于解决方法,我做了一些简单的技巧。
在转到新 UI 之前ViewController 将标题设置为 ""
。并在 ViewDidAppear
方法中到达 ViewController 时按下后退按钮,再次设置标题。
后退按钮默认使用上一个视图控制器的标题。所以你需要改变前一个视图控制器的标题来改变后退按钮的标题。
要隐藏标题,可以使用SetBackButtonTitlePositionAdjustment设置标题的偏移量,并通过在偏移量中传递(-80,-80)将标题移动到按钮的不可见区域。
试试这个
this.NavigationItem.SetLeftBarButtonItem(new UIBarButtonItem("text", UIBarButtonItemStyle.Plain , (sender, args) => { }), true);
在做PushViewController之前可以在parent controller中这样设置
this.NavigationItem.BackBarButtonItem = new UIBarButtonItem("", UIBarButtonItemStyle.Plain, null);