IOS quartz2d Simulation Download progress bar

Source: Internet
Author: User

:

Steps:

1. Drag a controller into the storyboard add UISlider and UIView 2 controls

2. Monitor the value change event, Hjprogressview property of the UISlider in the controller, and pass the changed value to the custom UIView

3. Custom Hjprogressview Override the Progressvalue property set method to redraw the text and Radian values in the view

Controller code:

#import "ViewController.h" #import "HJProgressView.h" @interface Viewcontroller () @property (Nonatomic,strong) Iboutlet Hjprogressview *progressview;-(ibaction) Didslidervaluechange: (UISlider *) sender; @end @implementation viewcontroller-(void) viewdidload {    [super viewdidload];    Do any additional setup after loading the view, typically from a nib.} -(void) didreceivememorywarning {    [super didreceivememorywarning];    Dispose of any resources the can be recreated.} /** *  sender.value value 0.0~1.0 * *  @param sender < #sender description#> */-(ibaction) Didslidervaluechange: ( UISlider *) Sender {    NSLog (@ "%f", sender.value);    Self.progressView.progressValue = Sender.value;} @end

Custom View Code:

hjprogressview.m//Draw progress bar////Created by Hjiang on 15/1/2.//Copyright (c) 2015 Hjiang. All rights reserved.//#import "HJProgressView.h" @interface Hjprogressview ()//define properties to save the last Radian start//@property (nonatomic, Assign) CGFloat Endangle, @end @implementation hjprogressview-(void) Setprogressvalue: (float) progressvalue{_        Progressvalue = Progressvalue; Redraw Progressview graphics [self setneedsdisplay];} /** * Draw Progress bar * x, y Center * radius radius * StartAngle The starting position of the arc * Endangel arc End position * Clockwise 0 Shun pin 1 counterclockwise * @param rect rect    Description */-(void) DrawRect: (cgrect) rect{//1. Set Progress text cgfloat w = 40;    CGFloat h = 30;    CGFloat x = 13;    CGFloat y = rect.size.height/2-5;//nsstring *progresstext = [NSString stringwithformat:@ "%.02f", Self.progressValue];    Output progress percentage number nsmutablestring *progresstext = [nsmutablestring string];    [Progresstext appendformat:@ "%.01f", Self.progressvalue * 100];        [Progresstext appendstring:@ "%"]; Control text font size and color properties Nsdictionary *attrs = @{nsfontattributename:[uifont Systemfontofsize:10],nsforegroundcolorattributename:[uicolor RedColor]};        [Progresstext drawinrect:cgrectmake (x, Y, W, h) withattributes:attrs];    Cgcontextref CTX = Uigraphicsgetcurrentcontext ();        Set the color Cgcontextsetrgbstrokecolor (CTX, 0.5, 0.5, 0.5, 1);        Set the line size Cgcontextsetlinewidth (CTX, 3);        2. Draw the arc progress cgfloat endangle = Self.progressvalue * 2 * M_PI-M_PI_4;        Cgcontextaddarc (CTX, 25,-m_pi_4, Endangle, 0);    Cgcontextstrokepath (CTX); } @end

IOS quartz2d Simulation 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.