iosquartz2d-02-drawing a cool download progress bar

Source: Internet
Author: User

Implementation ideas
    • To implement a drawing, you typically need to customize a UIView subclass, overriding the-(void) DrawRect: (CGRect) Rect method of the parent class, implementing the drawing operation in the method
    • To display the download progress, you only need to instantiate the object of the custom subclass (if the control in storyboard, just modify the control's Class property to customize the subclass name)
    • The effect shown is actually to draw an arc, dynamically change the position of the end point, and finally reach a closed circle
    • The middle text is a Uilabel control that dynamically changes the reality of the text according to the progress
Implementation steps
  • Customizing a subclass of UIView

    //提供一个成员属性,接收下载进度值@property (nonatomicassignCGFloat progress;
  • Overriding the setter of member properties progress

    //每次改变成员属性progress的值,就会调用它的setter- (void)setProgress:(CGFloat)progress{    _progress = progress;    //当下载进度改变时,手动调用重绘方法    [self setNeedsDisplay];}
  • Rewrite-(void) DrawRect: (cgrect) rect ( 核心 )

    - (void) DrawRect: (CGRect) rect{//Set radius of Arc    CGFloatRadius = rect. Size. Width*0.5;//Set the center of the arc    CgpointCenter = cgpointmake (radius, radius);//Set the starting angle of the arc (in radians)    CGFloatStartAngle =-m_pi_2;//Set the end angle of the arc    CGFloatEndangle =-M_pi_2 +2* M_PI * Self. Progress;//Use the Uibezierpath class to draw arcsUibezierpath *path = [Uibezierpath bezierpathwitharccenter:center Radius:radius-5Startangle:startangle Endangle:endangle Clockwise:YES];//render the drawn arc onto the layer (that is, displayed)[Path stroke];}

    The latest status of this blog will be synced to Sina Weibo account: secular island

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

iosquartz2d-02-drawing a cool download progress bar

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.