您實際上需要提供您的繪圖例程,而不是調用基礎,並且當然需要根據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