@interface ViewController () { CAShapeLayer *shapeLayer; NSTimer *timer; } @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; / / as a first step, through setting the circular UIBezierPath UIBezierPath * circle vector path = [UIBezierPath bezierPathWithOvalInRect: CGRectMake (0, 0, 200, 200)]. CAShapeLayer *bgLayer = [CAShapeLayer layer]; CAShapeLayer = [bgLayer layer]; bgLayer.frame = CGRectMake(0, 0, 200, 200); // Set Frame bglayer.position = self.view.center; // Center bglayer.fillcolor = [UIColor clearColor].cgcolor; // Fill color = transparent bglayer. lineWidth = 2.f; // line size bglayer.strokecolor = [UIColor grayColor].cgcolor; // line color bglayer.strokestart = 0.f; // Path start position bglayer.strokeend = 1.f; // End of path bglayer.path = circle.cgpath; // Set bgLayer to circle [self.view.layer addSublayer:bgLayer]; ShapeLayer = [CAShapeLayer]; shapeLayer = [CAShapeLayer layer]; shapeLayer.frame = CGRectMake(0, 0, 200, 200); shapeLayer.position = self.view.center; shapeLayer.fillColor = [UIColor clearColor].CGColor; shapeLayer.lineWidth = 2.f; shapeLayer.strokeColor = [UIColor redColor].CGColor; shapeLayer.strokeStart = 0; shapeLayer.strokeEnd = 0; shapeLayer.path = circle.CGPath; [self.view.layer addSublayer:shapeLayer]; // Step 4, test with a timer. Every second, Progress and 10% timer = [NSTimer scheduledTimerWithTimeInterval: 1 f target: self selector: @ the selector (the animate) the userInfo: nil repeats:YES]; } - (void)animate {shapelayer. strokeEnd += 0.1; }Copy the code