问题描述
我正在使用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
};