我正在尝试为xamarin形式的ios创建渐变progressbarcolor。我有一个可以站立的底座,但是它看起来并不像我想要的那样。
我尝试完成的是具有渐变颜色的progressbarcolor。使用当前结果,整个进度栏都有一个渐变(包括背景),这不是我想要的。想法是仅将progressbarcolor设为渐变。
渲染器:
public class ProgressBar_iOS : VisualElementRenderer<ProgressBar>
{
public override void Draw(CGRect rect) {
base.Draw(rect);
IProgressBar stack = (IProgressBar)this.Element;
CGColor startColor = stack.StartColor.ToCGColor();
CGColor endColor = stack.EndColor.ToCGColor();
#region for Vertical Gradient
//var gradientLayer = new CAGradientLayer();
# endregion
# region for Horizontal Gradient
var gradientLayer = new CAGradientLayer() {
StartPoint = new CGPoint(0, 0.5),
EndPoint = new CGPoint(1, 0.5)
};
#endregion
gradientLayer.Frame = rect;
gradientLayer.Colors = new CGColor[] {
startColor,
endColor
};
NativeView.Layer.InsertSublayer(gradientLayer, 0);
}
}
班级:
public static void Init()
{
}
public static readonly BindableProperty StartColorProperty =
BindableProperty.Create<GradientColor, Color>(
p => p.StartColor, Color.White);
public static readonly BindableProperty EndColorProperty =
BindableProperty.Create<GradientColor, Color>(
p => p.EndColor, Color.White);
public Color StartColor
{
get { return (Color)GetValue(StartColorProperty); }
set { SetValue(StartColorProperty, value); }
}
public Color EndColor
{
get { return (Color)GetValue(EndColorProperty); }
set { SetValue(EndColorProperty, value); }
}
XAML:
<controls:IProgressBar
ProgressColor="#B24592"
EndColor="#F15F79"
Progress = "0.5" />
结果是这样,整个进度条是一个渐变,而不是Progresscolor: