IOS Development Custom Bar Progressview instance _ios

Source: Internet
Author: User

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!

Related Article

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.