Progress bar for iPhone Customization

Source: Internet
Author: User
Progress bar for iPhone Customization

Train of Thought: instead of inheriting uiprogressview, It inherits uiview and adds two uiimageviews. One is a back image, and then adds a fill image to it and sets the X coordinate to the leftmost of the screen, then, a timer changes the X coordinates of the fill graph at intervals to achieve the effect similar to the progress.

:

Code:

Customprogress. h

//// Customprogress. h // chok_passenger /// created by Ren haili on 13-7-11. // copyright (c) Ren haili in December 2013. all rights reserved. // # import <uikit/uikit. h> @ protocol customprogressdelegate <nsobject> // modify the progress TAG content-(void) changetextprogress :( nsstring *) string; // end of the progress bar-(void) endtime; @ end @ interface customprogress: uiview // background image @ property (retain, nonatomic) uiimageview * trackview; // fill the image @ property (retain, nonatomic) uiimageview * progressview; @ property (retain, nonatomic) nstimer * progresstimer; // time timer @ property (nonatomic) cgfloat targetprogress; // progress @ property (nonatomic) cgfloat currentprogress; // current progress @ property (nonatomic, strong) ID <customprogressdelegate> delegate;-(void) setprogress :( cgfloat) progress; // sets the progress @ end

Customprogress. m

//// Customprogress. M // chok_passenger /// created by Ren haili on 13-7-11. // copyright (c) Ren haili in December 2013. all rights reserved. // # import "customprogress. H "@ implementation customprogress-(ID) initwithframe :( cgrect) frame {self = [Super initwithframe: frame]; If (Self) {self. backgroundcolor = [uicolor clearcolor]; // background image _ trackview = [[uiimageview alloc] initwithframe: cgrectmake (0, 0, frame. size. width, frame. size. height)]; [_ trackview setimage: [uiimage imagenamed: @ "wait_progress_back.png"]; _ trackview. clipstobounds = yes; // The main function of the current view is to cut the out-of-the-box _ progressview. Therefore, set clipstobounds to Yes [self addsubview: _ trackview]; // fill in the image _ progressview = [[uiimageview alloc] initwithframe: cgrectmake (0-frame.size.width, 0, frame. size. width, frame. size. height)]; [_ progressview setimage: [uiimage imagenamed: @ "wait_progress.png"]; [_ trackview addsubview: _ progressview]; _ currentprogress = 0.0;} return self ;} -(void) setprogress :( cgfloat) Progress {If (0 = progress) {self. currentprogress = 0; [self changeprogressviewframe]; return;} _ targetprogress = progress; If (_ progresstimer = nil) {// create timer _ progresstval = [nstimer scheduledtimerwithtimeinterval: 1 target: self selector: @ selector (moveprogress) userinfo: Nil repeats: Yes];} //////////////////////////////////////// ////////////// modify the progress-(void) moveprogress {// determine whether the current progress is greater than the progress value if (self. currentprogress <_ targetprogress) {self. currentprogress = min (self. currentprogress + 0.1 * _ targetprogress, _ targetprogress); If (_ targetprogress> = 10) {[_ delegate changetextprogress: [nsstring stringwithformat: @ "% d %", (INT) self. currentprogress];} else {[_ delegate changetextprogress: [nsstring stringwithformat: @ "%. 1f % ", self. currentprogress];} // change the interface content [self changeprogressviewframe];} else {// when the progress is exceeded, end the timer and process the proxy method [_ progresstimer invalidate]; _ progresstimer = nil; [_ delegate endtime] ;}// modify the display content-(void) changeprogressviewframe {// you only need to change the X coordinate of the frame to see the effect of the same progress _ progressview. frame = cgrectmake (self. frame. size. width * (_ currentprogress/_ targetprogress)-self. frame. size. width, 0, self. frame. size. width, self. frame. size. height);} @ end

Fixed Link:
Http://www.zhouxiaodong.net /? P = 99 | Station of the melancholy little cave

Download link: http://download.csdn.net/detail/rhljiayou/5870535

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.