效果圖

ezgif.com-video-to-gif.gif
使用方法
/**
* 提示文案
* 默認 正在加載
*/
+ (nonnull GYProgressView *)gy_showProgressWithAlertStr:(NSString *_Nullable)alertStr progressFinishedHandle:(void(^)(void))progressFinishedHandle;
/**
* 設置進度
*/
- (void)setProgressWithPercentage:(CGFloat)percentage;
/**
* 銷毀頁面
*/
- (void)gy_dismissView;
核心代碼
- 1、繪制圓
// 黑色的背景框
CAShapeLayer *bordLayer = [CAShapeLayer layer];
UIBezierPath *bordPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, 148, 116) byRoundingCorners:UIRectCornerAllCorners cornerRadii:CGSizeMake(6, 6)];
bordLayer.path = bordPath.CGPath;
self.alertView.layer.mask = bordLayer;
// 進度的底色
UIBezierPath *bgRoundPath = [UIBezierPath bezierPathWithArcCenter:CGPointMake(20, 20) radius:20 startAngle:0 endAngle:M_PI * 2 clockwise:YES];
self.bgProgressLayer.path = bgRoundPath.CGPath;
[self.bgProgressView.layer addSublayer:self.bgProgressLayer];
// 進度的顏色
UIBezierPath *roundPath = [UIBezierPath bezierPathWithArcCenter:CGPointMake(20, 20) radius:20 startAngle:-M_PI_2 endAngle:-M_PI_2 + M_PI *2 clockwise:YES];
self.progressLayer.path = roundPath.CGPath;
[self.progressView.layer addSublayer:self.progressLayer];
self.progressLayer.strokeStart = 0;
self.progressLayer.strokeEnd = 0;
- 2、設置進度
_progressLayer.strokeEnd = _percentage;
NSString *str = [NSString stringWithFormat:@"%.0f%%",_percentage*100];
_progressLabel.text = str;
注意事項
為防止 外界set 值過快, 導致 實際顯示跟 值有差值,設定一個定時器定時去取值
- (void)setProgressWithPercentage:(CGFloat)percentage {
self.percentage = percentage;
if (self.timer == nil && !self.canRemoveTimer) {
self.timer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(updataUI) userInfo:nil repeats:YES];
}
}