我想在图像上绘制一条路径,代表Xamarin中的半进度条。然后它适用于顶部。
但现在我想画出底部。但我尝试过尝试再试一次但没有找到任何东西。
图像会解释你。 Image
代码:
public CircleGraph(UIImageView imageView, int lineWidth, float percentComplete) : base(imageView.Frame)
{
Initialise(imageView, lineWidth, percentComplete);
}
void Initialise(UIImageView imageView, int lineWidth, float percentComplete)
{
_lineWidth = lineWidth;
_percentComplete = percentComplete;
this.BackgroundColor = UIColor.Clear;
this.backgroundImage = imageView;
Add(backgroundImage);
centerPoint = new CGPoint(Bounds.GetMidX(), Bounds.Height);
maskLayer = new CAShapeLayer();
maskLayer.FillColor = UIColor.Blue.CGColor;
maskLayer.StrokeColor = UIColor.Black.ColorWithAlpha(.5f).CGColor;
maskLayer.LineWidth = _lineWidth;
maskLayer.LineCap = CAShapeLayer.CapButt;
this.Layer.Mask = maskLayer;
}
public void SetClipping(float percentComplete) {
_percentComplete = percentComplete;
SetNeedsDisplay();
}
public override void Draw(CoreGraphics.CGRect rect)
{
base.Draw(rect);
using (CGContext g = UIGraphics.GetCurrentContext())
{
_radius = (int)(this.Bounds.Width / 2) - _lineWidth / 2;
// Top
var startAngle = -(float)Math.PI;
var endAngle = startAngle + HALF_CIRCLE * _percentComplete;
maskPath = new UIBezierPath();
maskPath.AddArc(centerPoint, _radius, startAngle, endAngle, false);
maskLayer.Path = maskPath.CGPath;
};
}
非常感谢!
答案 0 :(得分:0)
我找到了它!
将高度的centerPoint设为0,然后使用startAngle,endAngle和顺时针方向播放它就可以了!