在 Xamarin 中设置导航标题颜色(Ios)
Set Navigation Title color in Xamarin(Ios)
我想使用 C# 在 Xamarin(Ios) 中设置导航栏标题颜色。
我设置了下面的方法,但它不起作用。
this.NavigationController.NavigationBar.BarTintColor = UIColor.Clear.FromHexString("#0072BA", 1.0f);
this.NavigationController.NavigationBar.TitleTextAttributes = UIColor.Magenta;
BarTintColor
有效,但 TitleTextAttributes
无效。我也看到了文档,但在文档中没有提到标题文本颜色。
感谢任何帮助..
花了 1 小时后我得到了解决方案。
类型 UIKit.UINavigationBar
不包含 SetTitleTextAttributes
的定义,并且找不到类型 UIKit.UINavigationBar
的扩展方法 SetTitleTextAttributes
。它给出以下错误:
Are you missing an assembly reference ?
所以不要调用 SetTitleTextAttributes
,而是执行以下操作:
this.NavigationController.NavigationBar.TitleTextAttributes = new UIStringAttributes()
{
ForegroundColor = UIColor.White
};
希望这对其他人有所帮助。
您可以使用自定义视图作为导航栏的标题视图,方便修改。
在您的 "ViewDidLoad" 方法中,使用此代码:
public override void ViewDidLoad()
{
//Normal way
//this.Title = "Normal";//or this.NavigationItem.Title = "Normal;
//Using custom view
UILabel lbTitle = new UILabel(new CoreGraphics.CGRect(0, 0, 50, 30));
lbTitle.Text = "CustomView";
lbTitle.TextColor = UIColor.Red;
lbTitle.Font = UIFont.SystemFontOfSize(15);
this.NavigationItem.TitleView = lbTitle;
//Using a picture
//this.NavigationItem.TitleView = new UIImageView();
}
希望对您有所帮助
我想使用 C# 在 Xamarin(Ios) 中设置导航栏标题颜色。
我设置了下面的方法,但它不起作用。
this.NavigationController.NavigationBar.BarTintColor = UIColor.Clear.FromHexString("#0072BA", 1.0f);
this.NavigationController.NavigationBar.TitleTextAttributes = UIColor.Magenta;
BarTintColor
有效,但 TitleTextAttributes
无效。我也看到了文档,但在文档中没有提到标题文本颜色。
感谢任何帮助..
花了 1 小时后我得到了解决方案。
类型 UIKit.UINavigationBar
不包含 SetTitleTextAttributes
的定义,并且找不到类型 UIKit.UINavigationBar
的扩展方法 SetTitleTextAttributes
。它给出以下错误:
Are you missing an assembly reference ?
所以不要调用 SetTitleTextAttributes
,而是执行以下操作:
this.NavigationController.NavigationBar.TitleTextAttributes = new UIStringAttributes()
{
ForegroundColor = UIColor.White
};
希望这对其他人有所帮助。
您可以使用自定义视图作为导航栏的标题视图,方便修改。
在您的 "ViewDidLoad" 方法中,使用此代码:
public override void ViewDidLoad()
{
//Normal way
//this.Title = "Normal";//or this.NavigationItem.Title = "Normal;
//Using custom view
UILabel lbTitle = new UILabel(new CoreGraphics.CGRect(0, 0, 50, 30));
lbTitle.Text = "CustomView";
lbTitle.TextColor = UIColor.Red;
lbTitle.Font = UIFont.SystemFontOfSize(15);
this.NavigationItem.TitleView = lbTitle;
//Using a picture
//this.NavigationItem.TitleView = new UIImageView();
}
希望对您有所帮助