////RPProgressView.h//Calayer Customizing the Download progress bar control////Created by Rinpechen on 16/1/2.//copyright©2016 year RINPE. All rights reserved.//#import<UIKit/UIKit.h>@interfaceRpprogressview:uiview@property (nonatomic, assign) CGFloat progressvalue; //Progress Value: 0 ~ 1.0@property (nonatomic, strong) Uicolor *progresscolor;//progress bar Color@end
////rpprogressview.m//Calayer Customizing the Download progress bar control////Created by Rinpechen on 16/1/2.//copyright©2016 year RINPE. All rights reserved.//#import "RPProgressView.h"@interfaceRpprogressview () @property (nonatomic, strong) Calayer*Progresslayer;@end@implementationRpprogressview-(Instancetype) initWithFrame: (cgrect) frame{ Self=[Super Initwithframe:frame]; if(self) {//Initialize LayerSelf.progresslayer =[Calayer layer]; Self.progressLayer.backgroundColor=[Uicolor Redcolor]. Cgcolor; Self.progressLayer.frame= CGRectMake (0,0,0, Frame.size.height); //Add a child layer[Self.layer AddSublayer:self.progressLayer]; } returnSelf ;}- (void) Setframe: (CGRect) frame{[Super Setframe:frame]; Self.progressLayer.frame= CGRectMake (0,0,0, frame.size.height);}//Set Progress Values- (void) Setprogressvalue: (cgfloat) progressvalue{_progressvalue=Progressvalue; if(Progressvalue <=0) {Self.progressLayer.frame= CGRectMake (0,0,0, Self.frame.size.height); } Else if(Progressvalue <=1) {Self.progressLayer.frame= CGRectMake (0,0, Self.frame.size.width *Progressvalue, self.frame.size.height); } Else{self.progressLayer.frame= CGRectMake (0,0, Self.frame.size.width, self.frame.size.height); }}//Set the progress bar color- (void) Setprogresscolor: (Uicolor *) progresscolor{_progresscolor=Progresscolor; Self.progressLayer.backgroundColor=Progresscolor.cgcolor;}@end
Demo:https://github.com/rinpechen/progressviewdemobyrinpe.git
Customizing the download progress bar control with Calayer