【发布时间】:2015-03-16 12:21:22
【问题描述】:
我正在使用 Xamarin.Forms 并尝试更改 iOS 上导航栏的背景颜色。
我有一个从 NavigationPage 继承的自定义导航栏类,具有可绑定的属性和构造函数,用于设置导航栏的颜色。据我了解,导航栏顶部有一个默认背景(黑色) Xamarin.Forms 导航背景。我可以使用 SetColor() 方法设置背景颜色(见下文)。但是,它留下了一条黑线,这是导航栏(iOS)的背景,如图所示。 Picture Link
现在,我正在尝试将 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;
}
}
}
}
【问题讨论】:
标签: c# xamarin.forms