簡體   English   中英

在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 instanceobject is not set to instance

有沒有辦法在iOS中將“后退”按鈕標題設置為null。

任何幫助將不勝感激。

后退標題取決於ViewController的Title屬性。

它可以如下設置,這里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/

上面的鏈接詳細說明。 如果您在執行此操作時遇到問題,也請在此之后通知我。

對於變通辦法,我做一些簡單的技巧。

在轉到新的UIViewController之前,將Title設置為"" 然后,當您進入ViewDidAppear方法內的ViewController時,請按Back按鈕,再次設置Title。

“后退”按鈕默認使用上一個視圖控制器中的標題。 因此,您需要更改veiw控制器的前一個標題才能更改后退按鈕標題。

若要隱藏標題,可以使用SetBackButtonTitlePositionAdjustment設置Title的偏移量,並通過在偏移量中傳遞(-80,-80)將標題移動到按鈕的不可見區域。

嘗試這個

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

您可以在執行PushViewController之前在父控制器中像這樣設置

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM