Sgt*_*nut 3 user-interface xaml ios xamarin
我想在 iOS 上的 Xamarin 中隐藏后退按钮的文本,我试过:
<Style TargetType="NavigationPage">
<Setter Property="BackButtonTitle" Value="" />
</Style>
Run Code Online (Sandbox Code Playgroud)
和这个代码:
<Style TargetType="ContentPage">
<Setter Property="NavigationPage.BackButtonTitle" Value="" />
</Style>
Run Code Online (Sandbox Code Playgroud)
但文字仍然出现
解决了:
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);
}
}
Run Code Online (Sandbox Code Playgroud)
也添加这个
NavigationPage.BackButtonTitle = ""
Run Code Online (Sandbox Code Playgroud)
到 MasterDetailPage 的 Main.xaml
正如这里所说,您可以为后退按钮标题使用空字符串:
NavigationPage.SetBackButtonTitle(this, "");
Run Code Online (Sandbox Code Playgroud)
或者您可以将标题设置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;
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1520 次 |
最近记录: |