Xamarin.forms NavigationBar Title 为 IOS 设置文本颜色

Xamarin.forms NavigationBar Title set text color for IOS

我正在开发 xamarin.forms 应用程序,我想更改我的标题颜色。我添加了 android 并且工作正常,但是 IOS 不知道如何更改。我添加了状态栏设计

        public override void OnActivated(UIApplication uiApplication)
        {
 
            if (UIDevice.CurrentDevice.CheckSystemVersion(13, 0))
            {
                // If VS has updated to the latest version , you can use StatusBarManager , else use the first line code
                // UIView statusBar = new UIView(UIApplication.SharedApplication.StatusBarFrame);
                UIView statusBar = new UIView(UIApplication.SharedApplication.KeyWindow.WindowScene.StatusBarManager.StatusBarFrame);
                statusBar.BackgroundColor = Color.FromHex("07987f").ToUIColor(); 
                statusBar.TintColor= Color.FromHex("07987f").ToUIColor();    
                
                UIApplication.SharedApplication.KeyWindow.AddSubview(statusBar);
            }
            else
            {
                UIView statusBar = UIApplication.SharedApplication.ValueForKey(new NSString("statusBar")) as UIView;
                if (statusBar.RespondsToSelector(new ObjCRuntime.Selector("setBackgroundColor:")))
                {
                    statusBar.BackgroundColor = Color.FromHex("07987f").ToUIColor(); 
                    statusBar.TintColor= Color.FromHex("07987f").ToUIColor();
                }
            }
            base.OnActivated(uiApplication);
        }

状态栏和导航栏设计都可以:

            UINavigationBar.Appearance.BarTintColor = Color.FromHex("07987f").ToUIColor();
            UINavigationBar.Appearance.TintColor = Color.White.ToUIColor();
            

但标题颜色是 Black。有什么建议吗?

这里TintColor属性改变导航栏的背景颜色

BarTintColor 属性影响

的颜色
  • 后退指标图像
  • 按钮标题
  • 按钮图片

因此在您的情况下,设置标题的 TextColor 您可以调用以下代码。

UINavigationBar.Appearance.TitleTextAttributes = new UIStringAttributes
{
    ForegroundColor = UIColor.White
};