IOS Custom progress bar Progressview, good progress bar, people pleasing, in the waiting time is not so irritable, but also to increase the user experience it!
Progress bar is very common in the development of iOS, I also wrote a lot of progress in the development of the project, there are many kinds of, bars, circles, etc., today to summarize a bar of the development progress bar.
Simple idea:
1. The custom progress bar inherits UIView first to build a Custombarprogressview
2. Methods of leakage in. h Documents "Method of Initiation" "Initialization Method"
3. Use timer to change position in. m file to implement progress bar
#效果图
#部分代码
-(Instancetype) initWithFrame: (CGRect) frame withstartnum: (cgfloat) startnum withendnum: (cgfloat) EndNum WithSignNum
:(cgfloat) Signnum withtime: (cgfloat) time{if (self = [Super Initwithframe:frame]) {self.startnum = Startnum;
Self.endnum = Endnum;
Self.signnum = Signnum;
if (time = = 0) {self.time = 0.1;
}else{self.time = time;
} [self setupsubviews];
return self;
}-(void) Setupsubviews {UIView *backview = [[UIView alloc] init];
Backview.backgroundcolor =boomviewcolor;
BackView.layer.cornerRadius = Cornerradius;
BackView.layer.masksToBounds = YES;
[Self addsubview:backview];
Self.backview = Backview;
UIView *fontview = [[UIView alloc] init];
Fontview.backgroundcolor = Upviewcolor;
FontView.layer.cornerRadius = Cornerradius;
FontView.layer.masksToBounds = YES;
[Self addsubview:fontview];
Self.fontview = Fontview; }-(void) progressviewstart{if (Self.timer = = nil) {Dispatch_after dispatch_time (dispatch_tiMe_now, (int64_t) (0.1 * nsec_per_sec)), Dispatch_get_main_queue (), ^{self.timer = [Nstimer Scheduledtimerwithtimein
Terval:self.time target:self selector: @selector (changeprogressviewframe:) Userinfo:nil Repeats:yes];
[[Nsrunloop Mainrunloop] AddTimer:self.timer formode:nsrunloopcommonmodes];
}); }}-(void) Changeprogressviewframe: (Nstimer *) timer{//Position calculation cgfloat signprogress = (self.signnum-self.startnum)/
(Self.endnum-self.startnum);
NSLog (@ "==>>>%f", self.progress);
if (self.progress >= signprogress) {[Self.timer invalidate];
Self.timer = nil;
Return
} self.progress = 0.01;
[Self setneedslayout];
}-(void) layoutsubviews{[Super Layoutsubviews];
NSLog (@ "==>>>%f", self.progress);
Self.backView.frame = Self.bounds;
Self.fontView.frame = Self.bounds;
Self.fontView.width = Self.width * self.progress;
}
PS: You can increase your own progress bar text and so on to modify the size style
Don't underestimate anyone, the less humble people. Often do things that are unexpected ...
Thank you for reading, I hope to help you, thank you for your support for this site!