我喜欢Xcode中的小型饼状进度条,当在项目中搜索字符串(Shift-Command-F)时,可以看到图片。
如何在iOS上调用它?我希望在下载队列中使用它。
提前感谢。
我喜欢Xcode中的小型饼状进度条,当在项目中搜索字符串(Shift-Command-F)时,可以看到图片。
如何在iOS上调用它?我希望在下载队列中使用它。
提前感谢。
没有现成的循环确定进度视图。以下是一个drawRect:
示例,您可以使用它来实现这样的视图。
- (void)drawRect:(CGRect)rect
{
CGFloat circleRadius = (self.bounds.size.width / 2) - (self.strokeWidth * 2);
CGPoint circleCenter = CGPointMake(CGRectGetMidX(rect), CGRectGetMidY(rect));
CGRect circleRect = CGRectMake(circleCenter.x - circleRadius, circleCenter.y - circleRadius, 2 * circleRadius, 2 * circleRadius);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSaveGState(context);
// Draw stroked circle to delineate circle shape.
CGContextSetStrokeColorWithColor(context, self.fillColor.CGColor);
CGContextSetLineWidth(context, self.strokeWidth);
CGContextAddEllipseInRect(context, circleRect);
CGContextStrokePath(context);
// Draw filled wedge (clockwise from 12 o'clock) to indicate progress
self.progress = MIN(MAX(0.0, self.progress), 1.0);
CGFloat startAngle = -M_PI_2;
CGFloat endAngle = startAngle + (progress * 2 * M_PI);
CGContextSetFillColorWithColor(context, self.fillColor.CGColor);
CGContextMoveToPoint(context, circleCenter.x, circleCenter.x);
CGContextAddLineToPoint(context, CGRectGetMidX(circleRect), CGRectGetMinY(circleRect));
CGContextAddArc(context, circleCenter.x, circleCenter.y, circleRadius, startAngle, endAngle, NO);
CGContextClosePath(context);
CGContextFillPath(context);
CGContextRestoreGState(context);
}
您需要创建strokeWidth
和fillColor
属性才能直接使用此代码,但这应该是一个开始。这里有一个带有几个示例的样品项目。
UIProgressView
,但你可以自己创建。要将事物放在文本视图的右侧,请使用rightView
属性(不要忘记设置rightViewMode
)。UIView
(我怀疑它值得尝试来子类化UIProgressView
)。我可能会用drawRect
手绘它,而不是尝试使用任何图片或其他东西。这样更容易填充正确的百分比。试一下这个:LSPieProgressView
它是一个UIView类别,可以在任何UIView上显示一个饼图进度覆盖层。
代码示例:
#import "UIView+LSPieProgress.h"
- (void)updateProgress
{
[self.button setProgress:self.progress];
}
CALayer
中的进度属性,但这是真实的。对于读者来说,这绝对是一个有趣的练习。 - warrenm