目标效果

实现
新建基于UIview的文件
.h
属性
- /** 0 < accuracy < 1 */
- @property (nonatomic,assign) double accuracy;
.m
属性
- ///画圆Layer
- @property (nonatomic,strong) CAShapeLayer *shapeLayer;
- ///底层灰色圆Layer
- @property (nonatomic,strong) CAShapeLayer *shapeFloorLayer;
- ///画圆Path
- @property (nonatomic,strong) UIBezierPath *proPath;
- @property (nonatomic,strong) UILabel * accuracyLabel;
- @property (nonatomic,strong) UICountingLabel * aValueLabel;
- ///圆心
- @property (nonatomic,assign) CGPoint roundCenter;
- ///圆半径
- @property (nonatomic, assign) CGFloat radius;
方法
备注
代码中用到了SDAutoLayout约束,pop 动画、UICountingLabel 第三方 label 数字动画,UICountingLabel 的 format 原本不支持的百分比格式,如若需要可在源码中 setTextValue 修改:
修改前
- - (void)setTextValue:(CGFloat)value
- {
- if (self.attributedFormatBlock != nil) {
- self.attributedText = self.attributedFormatBlock(value);
- }
- else if(self.formatBlock != nil)
- {
- self.text = self.formatBlock(value);
- }
- else
- {
- // check if counting with ints - cast to int
- if([self.format rangeOfString:@"%(.*)d" options:NSRegularExpressionSearch].location != NSNotFound ||
- [self.format rangeOfString:@"%(.*)i"].location != NSNotFound)
- {
- self.text = [NSString stringWithFormat:self.format,(int)value];
- }
- else
- {
- self.text = [NSString stringWithFormat:self.format,value];
- }
- }
- }
修改后
- - (void)setTextValue:(CGFloat)value
- {
- if (self.attributedFormatBlock != nil) {
- self.attributedText = self.attributedFormatBlock(value);
- }
- else if(self.formatBlock != nil)
- {
- self.text = self.formatBlock(value);
- }
- else
- {
- // check if counting with ints - cast to int
- if([self.format rangeOfString:@"%(.*)d%%" options:NSRegularExpressionSearch].location != NSNotFound ||
- [self.format rangeOfString:@"%(.*)i%%"].location != NSNotFound ||
- [self.format rangeOfString:@"%(.*)d" options:NSRegularExpressionSearch].location != NSNotFound ||
- [self.format rangeOfString:@"%(.*)i"].location != NSNotFound)
- {
- self.text = [NSString stringWithFormat:self.format,(int)value];
- }
- else
- {
- self.text = [NSString stringWithFormat:self.format,value];
- }
- }
- }