IOSQuartz2D-02-draw cool download progress bars
Implementation To implement plotting, you usually need to define a subclass of UIView, override the parent class's-(void) drawRect :( CGRect) rect method, to display the download progress, you only need to instantiate the custom subclass object (if it is a control in storyboard, you only need to modify the class attribute of the control to the class Name of the custom subclass)
The effect shown in is actually to draw an arc, dynamically changing the end point position, and finally reaching a closed circle in the middle of the text is a UILabel control, based on the progress of dynamic change of the actual implementation steps of the text
Customize a subclass of A UIView
// Provide a member attribute to receive the download progress value @ property (nonatomic, assign) CGFloat progress;
Override the setter of the member attribute progress
// The setter-(void) setProgress (CGFloat) progress {_ progress = progress is called every time the value of the member property progress is changed; // when the download progress changes, manually call the redrawing method [self setNeedsDisplay];}
Override-(void) drawRect :( CGRect) rect (Core
)
-(Void) drawRect :( CGRect) rect {// set the Arc radius CGFloat radius = rect. size. width * 0.5; // set the center of the arc CGPoint center = CGPointMake (radius, radius); // set the angle of the arc (in radians) CGFloat startAngle =-M_PI_2; // set the arc termination angle CGFloat endAngle =-M_PI_2 + 2 * M_PI * self. progress; // use the UIBezierPath class to draw an arc UIBezierPath * path = [UIBezierPath bezierPathWithArcCenter: center radius: radius-5 startAngle: startAngle endAngle: endAngle clockwise: YES]; // render the drawn arc to the layer (displayed) [path stroke];}