#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)