IOSQuartz2D-02-draw cool download progress bars

Source: Internet
Author: User

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];}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.