ios - 在 Xamarin 中隐藏后退按钮文本
问题描述
我想在 iOS 上的 Xamarin 中隐藏后退按钮的文本,我尝试过:
<Style TargetType="NavigationPage">
<Setter Property="BackButtonTitle" Value="" />
</Style>
这个代码:
<Style TargetType="ContentPage">
<Setter Property="NavigationPage.BackButtonTitle" Value="" />
</Style>
但文字仍然出现
解决了:
iOS 渲染器:
[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);
}
}
还要加上这个
NavigationPage.BackButtonTitle = ""
到您的 MasterDetailPage 的 Main.xaml
解决方案
正如这里所说,您可以使用空字符串作为后退按钮标题:
NavigationPage.SetBackButtonTitle(this, "");
或者您可以将标题设置UIBarButtonItem
为清晰
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;
}
推荐阅读
- io - C fgets 函数的等效 Chapel 功能
- google-apps-script - 在我的 G Suite 域中的 Google 表格中记录工作表用户名时禁用脚本授权
- python - 数据集中的目标,图像 [0] sklearn
- r - 如何实现提取/分离功能(来自 dplyr 和 tidyr)以将一列分成多列。基于任意值?
- python - 抓取阿拉伯网站时从阿拉伯字母中获取奇怪的字母
- java - 如何使用 Java 查询 Grakn?
- javascript - 如何在 Jest 中的多个测试套件之间共享一个对象?
- elasticsearch - 将 Lucene 索引上传到 Kibana/ElasticSearch
- reactjs - 如何在反应中设置组件的条件属性
- c# - 无法让 UDP.BeginReceive 在 WPF 中工作