[英]iOS set BackButton in the current ViewController
How can I change the Back-Button of the currently displayed ViewController? 如何更改当前显示的 ViewController的后退按钮? Configuring the BackButtonItem effects the BackButton of the next ViewController, instead of the currently shown.
配置BackButtonItem会影响下一个ViewController的BackButton,而不是当前显示的BackButton。
eg: I have two ViewControllers VCA and VCB. 例如:我有两个ViewController VCA和VCB。 I navigate from VCA to VCB and want to style the BackButton thats shown on VCB.
我从VCA导航到VCB,并希望设置VCB上显示的BackButton的样式。 I want to hide the title and set custom icons for normal and highlighted state.
我想隐藏标题并为正常和突出显示状态设置自定义图标。
public class VCB : ViewControllerBase
{
public override void ViewDidLoad()
{
base.ViewDidLoad();
var btn = new UIBarButtonItem("", UIBarButtonItemStyle.Plain, null);
// TODO: set the Icon
NavigationItem.BackBarButtonItem = btn;
}
}
Do I have to implement my own BackButton and set it as LeftBarButton, or can I achieve this somehow with the standard BackButton . 我是否必须实现自己的BackButton并将其设置为LeftBarButton,还是可以使用标准BackButton某种方式实现呢?
如果BarButtonItem
在视图中已经有BarButtonItem
,则应该可以使用this.NavigationItem.BackBarButtonItem
并更改其属性。
You can try this in your ViewDidLoad
method: 您可以在
ViewDidLoad
方法中尝试以下方法:
UIBarButtonItem backButton = new UIBarButtonItem("< Back",UIBarButtonItemStyle.Plain, null);
this.NavigationItem.SetLeftBarButtonItem(backButton, false);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.