IOS Implementation Progress bar (progress)

Source: Internet
Author: User

#import<UIKit/UIKit.h>@interfacezsdprogressview:uiview{UIView*progressview;//Progress View}//Progress Value@property (nonatomic,assign)floatprogress;@end#defineUicolorfromrgb (rgbvalue) [Uicolor \colorwithred: ((float) ((Rgbvalue &0xFF0000) >> -))/255.0Green: ((float) ((Rgbvalue &0xff00) >>8))/255.0Blue: ((float) (Rgbvalue &0xFF))/255.0Alpha1.0]#import "ZSDProgressView.h"@implementationZsdprogressview-(ID) initWithFrame: (cgrect) frame{if(self=[Super Initwithframe:frame]) {Self.backgroundcolor=uicolorfromrgb (0xDADADA); }        returnSelf ;}-(void) awakefromnib{Self.backgroundcolor=uicolorfromrgb (0xDADADA); Progressview=[[UIView alloc]init]; Progressview.translatesautoresizingmaskintoconstraints=NO;    [Self addsubview:progressview]; }-(void) Setprogress: (float) progress{_progress=progress; /** * Activepartview Add constraint*/        //left constraint[Self addconstraint:[nslayoutconstraint constraintwithitem:progressview attribute:nslayoutattributeleft relatedBy: Nslayoutrelationequal toitem:self Attribute:nslayoutattributeleft Multiplier:1constant0]]; //Upper Constraint[Self addconstraint:[nslayoutconstraint constraintwithitem:progressview attribute:nslayoutattributetop relatedBy: Nslayoutrelationequal toitem:self attribute:nslayoutattributetop Multiplier:1constant0]]; //Height Constraints[Self addconstraint:[nslayoutconstraint constraintwithitem:progressview attribute:nslayoutattributeheight Relatedby:nslayoutrelationequal Toitem:nil attribute:nslayoutattributeheight Multiplier:1Constant:self.frame.size.height]]; //width ConstraintsNslayoutconstraint *widthcon =[Nslayoutconstraint Constraintwithitem:progressview at Tribute:nslayoutattributewidth RELATEDBY:NSLAYOUTRELATIONEQ                                                                UAL toitem:self Attribute:nslayoutattributewidth mult IPLIER:_PROGRESS constant:0];    [Self Addconstraint:widthcon]; //fill background color with background mapUIImage *bgimage=[uiimage imagenamed:@"Invest_jindu"]; Uicolor*bgcolor=[Uicolor Colorwithpatternimage:bgimage];    [Progressview Setbackgroundcolor:bgcolor]; //Update constraint[Progressview needsupdateconstraints]; }@end
#import "ViewController.h"#import "ZSDProgressView.h"@interfaceViewcontroller () @property (weak, nonatomic) Iboutlet Zsdprogressview*Progressview;@end@implementationViewcontroller- (void) viewdidload {[Super viewdidload]; //additional setup after loading the view, typically from a nib.}- (void) didreceivememorywarning {[Super didreceivememorywarning]; //Dispose of any resources the can be recreated.}-(Ibaction) Setbtnclick: (UIButton *) sender{_progressview.progress=0.6; }@end

IOS Implementation Progress bar (progress)

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.