我有一个包含 WebView 的 ViewController。当我点击 WebView 中的电子邮件链接 (mailto:) 时,iOS 将推送一个允许用户撰写电子邮件的 ViewController。该 Controller 导航栏中的标题有黑色文本,我找不到更改颜色的方法。我能够更改导航栏的背景颜色以及按钮文本颜色,但不能更改标题颜色。
我正在使用 Xamarin (C#) 编写此应用程序,但如果作为解决方案提供,我应该能够翻译 Swift/Objective C 代码。
在我的应用程序委托(delegate)中,我设置了一些主题默认值。
UINavigationBar.Appearance.BarStyle = UIBarStyle.Black;
UINavigationBar.Appearance.BarTintColor = UIColor.Red;
UINavigationBar.Appearance.Translucent = false;
UINavigationBar.Appearance.TintColor = UIColor.White;
UINavigationBar.Appearance.SetTitleTextAttributes(new UITextAttributes()
{
TextColor = UIColor.White
});
UINavigationBar.Appearance.TitleTextAttributes.ForegroundColor = UIColor.White;
UIButton.AppearanceWhenContainedIn(typeof(UINavigationBar)).TintColor = UIColor.White;
我还在每个 ViewController 中设置了 this.NavigationController.NavigationBar.BarStyle = UIBarStyle.Black;
。我假设这就是问题所在。我无法在撰写电子邮件 View Controller 中设置 BarStyle,并且它似乎没有使用全局外观值。
最佳答案
在Xamarin.IOS 中:
如果想改变导航栏文字颜色,编码如下:
UIStringAttributes uIStringAttributes = new UIStringAttributes();
uIStringAttributes.ForegroundColor = UIColor.YouWantColor; //such as UIColor.Green
NavigationController.NavigationBar.TitleTextAttributes = uIStringAttributes;
如果想改变导航栏和状态栏,编码如下:
NavigationController.NavigationBar.BarTintColor = UIColor.YouWantColor;
// Color you want, such as UIColor.Green
关于ios - 撰写电子邮件时设置 UINavigationBar 标题颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56777613/