This article has drawn a cool download progress bar, share for everyone to reference, the specific content as follows
First, the realization of ideas
1. To implement a drawing, it is often necessary to customize a UIView subclass, overriding the parent-(void) DrawRect: (CGRect) Rect method, which implements drawing operations in this method
2, if you want to display the download progress, only need to instantiate the object of the subclass (if the control in the storyboard, just modify the control's class property for the custom subclass class name)
3, the effect of the results shown in fact is to draw a circular arc, dynamic change the end of the position, and finally reached a closed circle
4, the middle of the text is a Uilabel control, according to the progress of dynamic changes in the reality of the text
Second, the realization step
1. Customizing a UIView subclass
Provides a member property that receives the download progress value
@property (nonatomic, assign) cgfloat progress;
2. Overriding member properties Progress setter
Each time the value of the member property progress is changed, its setter
-(void) Setprogress: (cgfloat) Progress
{
_progress = progress is invoked;
Manually invoke the Redraw method
[self setneedsdisplay] when the download progress changes;
3, rewrite-(void) DrawRect: (cgrect) rect (CORE)
-(void) DrawRect: (cgrect) rect
{
//Set radius of Arc
cgfloat radius = rect.size.width * 0.5;
Set the center of the arc
cgpoint Center = cgpointmake (radius, radius);
Set the starting angle of the arc (radians)
cgfloat startangle =-m_pi_2;
Set the end angle of the arc
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];
Renders a drawn arc onto a layer (that is, displayed)
[path stroke];
}
The above is the entire content of this article, I hope to help you learn.