Xamarin.forms NavigationBar标题为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
};

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...