您实际上需要提供您的绘图例程,而不是调用基础,并且当然需要根据Progress
属性更改绘图。
一些简单的黄色矩形:
public override void Draw(CGRect rect)
{
var color = UIColor.FromRGBA(1.0f, 1.0f, 0.0f, 1.000f);
var rectanglePath = UIBezierPath.FromRect(new CGRect(rect.X, rect.Y, rect.Width * Progress, rect.Height));
color.SetFill();
rectanglePath.Fill();
}
或红色尖尖的thingie™:
public override void Draw(CGRect frame)
{
var context = UIGraphics.GetCurrentContext();
var color2 = UIColor.FromRGBA(0.199f, 0.018f, 0.018f, 1.000f);
var shadow = new NSShadow();
shadow.ShadowColor = UIColor.Black;
shadow.ShadowOffset = new CGSize(3.1f, 3.1f);
shadow.ShadowBlurRadius = 5.0f;
UIBezierPath bezierPath = new UIBezierPath();
bezierPath.MoveTo(new CGPoint(frame.GetMinX() + 0.00935f * frame.Width * Progress, frame.GetMinY() + 0.01351f * frame.Height));
bezierPath.AddLineTo(new CGPoint(frame.GetMinX() + 0.99537f * frame.Width * Progress, frame.GetMinY() + 0.50000f * frame.Height));
bezierPath.AddLineTo(new CGPoint(frame.GetMinX() + 0.99537f * frame.Width * Progress, frame.GetMinY() + 0.50000f * frame.Height));
bezierPath.AddLineTo(new CGPoint(frame.GetMinX() + 0.00935f * frame.Width * Progress, frame.GetMinY() + 0.98570f * frame.Height));
bezierPath.AddLineTo(new CGPoint(frame.GetMinX() + 0.00935f * frame.Width * Progress, frame.GetMinY() + 0.01351f * frame.Height));
bezierPath.ClosePath();
bezierPath.LineCapStyle = CGLineCap.Square;
bezierPath.LineJoinStyle = CGLineJoin.Bevel;
context.SaveState();
context.SetShadow(shadow.ShadowOffset, shadow.ShadowBlurRadius, shadow.ShadowColor.CGColor);
UIColor.Red.SetFill();
bezierPath.Fill();
context.RestoreState();
color2.SetStroke();
bezierPath.LineWidth = 1.0f;
bezierPath.Stroke();
}
感谢您的帮助,它看起来像这不是解决我的问题的最好方法。由于我不想丢失标准的'UIProgressView'的功能,我改写了自己的自定义类继承自'UIView',并将其绘制在应用程序中当前存在的'UIProgressView'上。您的详细答案帮助我了解当绘制方法被覆盖时在封面下发生了什么。 – PantAaroN