如何使用Xamarin更改iOS中NavigationController的标题文本颜色
我正在尝试使用如何使用Xamarin更改iOS中NavigationController的标题文本颜色,ios,uinavigationcontroller,xamarin.ios,xamarin,Ios,Uinavigationcontroller,Xamarin.ios,Xamarin,我正在尝试使用Xamarin更改iOS中NavigationController的标题文本颜色,但我无法更改它 有人能帮我实现吗?titleTextAttributes 显示栏标题文本的属性 @property(nonatomic, copy) NSDictionary *titleTextAttributes 讨论 您可以使用NSString UIKit Additions Reference中描述的文本属性键,在文本属性字典中为标题指定字体、文本颜色、文本阴影颜色和文本阴影偏移量。您不能直
Xamarin
更改iOS
中NavigationController
的标题文本颜色,但我无法更改它
有人能帮我实现吗?titleTextAttributes
显示栏标题文本的属性
@property(nonatomic, copy) NSDictionary *titleTextAttributes
讨论
您可以使用NSString UIKit Additions Reference中描述的文本属性键,在文本属性字典中为标题指定字体、文本颜色、文本阴影颜色和文本阴影偏移量。您不能直接更改它。仅通过外观或使用自己的视图作为标题。以下是在Xamarin.iOS中使用外观的解决方案:
UINavigationBar.Appearance.SetTitleTextAttributes(new UITextAttributes {
TextColor = UIColor.Purple
});
我试着用这种方法,它对我有效
var navigationBar = NavigationController.NavigationBar;
navigationBar.SetTitleTextAttributes(new UITextAttributes() { TextColor = UIColor.White });
萨提斯
编辑:
UINavigationBar
不再具有方法SetTitleTextAttributes
。相反,必须将TitleTextAttributes
属性设置为UIStringAttributes
属性,如下所示:
this.NavigationController.NavigationBar.TitleTextAttributes = new UIStringAttributes() { ForegroundColor = UIColor.White };
这篇文章很旧,但我认为这是你需要的:
this.NavigationController.NavigationBar.TitleTextAttributes = new UIStringAttributes() {
ForegroundColor = UIColor.White
};
曾为xamarin统一API工作过我认为这不再有效
UINavigationBar
没有SetTitleTextAttributes
方法,而是需要设置为UIStringAttributes
对象的属性TitleTextAttributes
。见@megaKertz答案<代码>this.NavigationController.NavigationBar.TitleTextAttributes=new-UIStringAttributes(){ForegroundColor=UIColor.White}代码>