国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統(tǒng) > iOS > 正文

IOS 開發(fā)自定義條形ProgressView的實例

2020-07-26 03:08:37
字體:
供稿:網(wǎng)友

IOS 自定義進(jìn)度條 ProgressView,好的進(jìn)度條,讓人賞心悅目,在等待的時候不是那么煩躁,也算是增加用戶體驗吧!

進(jìn)度條在iOS開發(fā)中很常見的,我在項目開發(fā)中也寫過好多進(jìn)度條,有好多種類的,條形,圓形等,今天給大家總結(jié)一種條形的開發(fā)進(jìn)度條。

簡單思路:

 1.自定義進(jìn)度條先繼承UIView 建立一個CustomBarProgressView
 2.在.H文件中外漏的方法《開始的方法》《初始化的方法》
 3.在.M文件中 利用定時器改變位置 實現(xiàn)進(jìn)度條

#效果圖

#部分代碼

-(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 scheduledTimerWithTimeInterval:self.time target:self selector:@selector(changeProgressViewFrame:) userInfo:nil repeats:YES];      [[NSRunLoop mainRunLoop] addTimer:self.timer forMode:NSRunLoopCommonModes];    });  }}-(void)changeProgressViewFrame:(NSTimer *)timer{  //位置計算  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:可以自己增加 進(jìn)度條文字等修改大小 樣式

別小看任何人,越不起眼的人。往往會做些讓人想不到的事。。。

感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 三亚市| 桓台县| 澄城县| 石屏县| 桐庐县| 贡山| 九寨沟县| 新干县| 湟中县| 治多县| 庆云县| 赫章县| 馆陶县| 湾仔区| 特克斯县| 大宁县| 香港 | 郁南县| 玉溪市| 广东省| 定安县| 鲁山县| 松溪县| 英吉沙县| 滨海县| 雷波县| 太仓市| 沙洋县| 隆化县| 博罗县| 融水| 定襄县| 鹿泉市| 浦东新区| 开封市| 抚松县| 仁怀市| 麟游县| 涟水县| 富宁县| 广昌县|