zoukankan      html  css  js  c++  java
  • ios

    #import <UIKit/UIKit.h>
    
    @interface TJCircleProgressView : UIView
    /**
     *  图标
     */
    @property(nonatomic,strong)UIImage *imgIcon;
    /**
     *  进度条值
     */
    @property(nonatomic,assign)CGFloat progressValue;
    /**
     *  进度条宽度
     */
    @property(nonatomic,assign)CGFloat progressWidth;
    
    /**
     *  进度条颜色
     */
    @property(nonatomic,strong)UIColor *progressColor;
    
    @end
    #import "TJCircleProgressView.h"
    @interface TJCircleProgressView ()
    {
        UIBezierPath *circlePath;//布赛尔曲线
        CAShapeLayer *shapeLayer;// 圆形图层
        CAShapeLayer *imgLayer;//图标图层
    
    }
    @end
    @implementation TJCircleProgressView
    @synthesize progressColor = _progressColor;
    @synthesize imgIcon = _imgIcon;
    @synthesize progressValue = _progressValue;
    @synthesize progressWidth = _progressWidth;
    
    - (instancetype)initWithFrame:(CGRect)frame
    {
        if (self = [super initWithFrame:frame])
        {
            self.backgroundColor = [UIColor whiteColor];
            circlePath = [UIBezierPath bezierPathWithOvalInRect:self.bounds];
            
            shapeLayer = [CAShapeLayer layer];
            shapeLayer.frame = self.bounds;
            shapeLayer.strokeColor = [UIColor redColor].CGColor;
            shapeLayer.fillColor   = [UIColor clearColor].CGColor;
            shapeLayer.path = circlePath.CGPath;
            
            shapeLayer.lineWidth   = 1.0f;
            [self.layer addSublayer:shapeLayer];
        }
        return self;
    }
    - (void)setImgIcon:(UIImage *)imgIcon
    {
        _imgIcon = imgIcon;
        imgLayer = [CAShapeLayer layer];
        imgLayer.frame = CGRectMake(0, 0, imgIcon.size.width, imgIcon.size.height);
        imgLayer.contents = (__bridge id)imgIcon.CGImage;
        imgLayer.position = shapeLayer.position;
        [self.layer addSublayer:imgLayer];
    
    }
    - (void)setProgressValue:(CGFloat)progressValue
    {
        _progressValue = progressValue;
        shapeLayer.strokeEnd = progressValue;
        [self startAnimation];
        /**延时4秒后移除动画以及view*/
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(4 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [self stopAnimation];
        });
      }
    - (void)setProgressWidth:(CGFloat)progressWidth
    {
        _progressWidth = progressWidth;
        shapeLayer.lineWidth = progressWidth;
    }
    - (void)setProgressColor:(UIColor *)progressColor
    {
        _progressColor = progressColor;
        shapeLayer.strokeColor = progressColor.CGColor;
    }
    -(void)startAnimation
    {
        [shapeLayer removeAnimationForKey:@"RotationAnimation"];
        
        CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
        animation.fromValue = @(0);
        animation.toValue = @(M_PI * 2);
        animation.repeatCount = MAXFLOAT;
        animation.duration = 0.5f;
        animation.fillMode = kCAFillModeForwards;
        
        [shapeLayer addAnimation:animation forKey:@"RotationAnimation"];
    }
    - (void)stopAnimation
    {
        [shapeLayer removeAllAnimations];
        [self removeFromSuperview];
    }
    @end
    #import "ViewController.h"
    #import "TJCircleProgressView.h"
    @interface ViewController ()
    {
        TJCircleProgressView *circleProgressView;
    }
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        circleProgressView = [[TJCircleProgressView alloc]initWithFrame:CGRectMake(0,0, 100, 100)];
        circleProgressView.center = self.view.center;
        [circleProgressView setProgressValue:0.75];
        [circleProgressView setProgressColor:[UIColor grayColor]];
        [circleProgressView setProgressWidth:1.0f];
        [circleProgressView setImgIcon:[UIImage imageNamed:@"refresh"]];
        [self.view addSubview:circleProgressView];
        
        
        
        
        
    }
    
    - (void)didReceiveMemoryWarning {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    
    @end

    ps:licecap录取动画没录好

  • 相关阅读:
    【学习】Filter
    黑马程序员JAVA基础String 类(上)
    黑马程序员JAVA基础基本数据类型对象包装类
    [xcode]安装xcode出现一个错误:The Installation Failed.
    [SW]SolidWorks文件属性(Properties)
    AutoCAD:使用VS2012调试AutoCAD 2010中.Net DLL类库
    AutoCAD:ObjectARX所有版本下载地址
    [IOS]如何让手上的 iPhone 或 iPad 进入 DFU 或 Recovery 模式
    [iOS]Win8下iTunes无法连接iPhone版本的解决方法
    [SW]SolidWorks API SDK二次开发学习心得01开发方式
  • 原文地址:https://www.cnblogs.com/thbbsky/p/4530493.html
Copyright © 2011-2022 走看看