我正在使用 Xamarin.Forms 并尝试更改 iOS 上导航栏的背景颜色。
我有一个继承自 NavigationPage 的自定义导航栏类,具有可绑定属性和构造函数,用于设置导航栏的颜色。根据我的理解,导航栏顶部有一个默认背景(黑色) Xamarin.Forms 导航背景。我可以使用 SetColor() 方法设置背景颜色(见下文)。然而,它留下了一条黑线,这是导航栏(iOS)的背景,如图所示。图片链接 http://s13.postimg.org/nei0pbjs7/nav.png
现在,我尝试将 iOS 导航栏背景颜色设置为白色或透明。我花了很多时间但没有任何效果。有人可以帮忙如何将背景设置为白色吗?
//PCL class
public class CustomNavigationalPage : NavigationPage
{
public static readonly BindableProperty BarBgColorProperty =
BindableProperty.
Create<CustomNavigationalPage, UIColor>
(p => p.BarBackgroundColorR, null);
public UIColor BarBackgroundColorR
{
get { return (UIColor)base.GetValue (BarBgColorProperty); }
set { base.SetValue (BarBgColorProperty, value); }
}
public NavigationalPageCustomized() : base()
{
SetColor();
}
void SetColor()
{
BarBackgroundColor = Color.Transparent;
BarTextColor = Color.Blue;
}
}
导航栏渲染器类:
[assembly: ExportRenderer (typeof (CustomNavigationalPage), typeof (CustomNavigationPageRenderer))]
namespace project.iOS
{
public class CustomNavigationPageRenderer : NavigationRenderer
{
public CustomNavigationPageRenderer()
{
// UINavigationBar.Appearance.SetBackgroundImage (UIImage.FromFile ("navbg.png"), UIBarMetrics.Default);
}
protected override void OnElementChanged (VisualElementChangedEventArgs args)
{
base.OnElementChanged (args);
var nb = (NavigationalPageCustomized) Element;
if (nb != null)
{
nb.BarBackgroundColorR = UIColor.White;
}
}
}
}
在您的中尝试此代码PCL of Xamarin.forms。更改下面的代码
App.xaml.cs 的构造函数。
public App()
{
MainPage = new NavigationPage(new Page1())
{
BarBackgroundColor = Color.Gray
};
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)