麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

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

iOS實(shí)現(xiàn)步驟進(jìn)度條功能實(shí)例代碼

2019-10-21 18:39:18
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

前言

在開(kāi)發(fā)中,我們經(jīng)常在很多場(chǎng)景下需要用到進(jìn)度條,比如文件的下載,或者文件的上傳等。 本文主要給大家介紹的是一個(gè)步驟進(jìn)度條效果,步驟進(jìn)度條效果參考

iOS,步驟,進(jìn)度條,例代碼

iOS UIKit 框架中并沒(méi)有提供類似的控件,我們可以使用 UIProgressView、UIView、UILabel 組合實(shí)現(xiàn)步驟進(jìn)度條效果。

  • UIProgressView——實(shí)現(xiàn)水平的進(jìn)度條效果;
  • UIView——把UIView裁剪成圓形,實(shí)現(xiàn)索引節(jié)點(diǎn)效果;
  • UILabel——每個(gè)節(jié)點(diǎn)下面的提示文字。

源碼

將步驟進(jìn)度條封裝成一個(gè) HQLStepView 類,它是 UIView 的子類。

HQLStepView.h 文件

#import <UIKit/UIKit.h>@interface HQLStepView : UIView// 指定初始化方法- (instancetype)initWithFrame:(CGRect)frame titlesArray:(NSArray *)titlesArray stepIndex:(NSUInteger)stepIndex;// 設(shè)置當(dāng)前步驟- (void)setStepIndex:(NSUInteger)stepIndex animation:(BOOL)animation;@end

HQLStepView.m 文件

#import "HQLStepView.h"// 步驟條主題色#define TINT_COLOR [UIColor colorWithRed:35/255.f green:135/255.f blue:255/255.f alpha:1]@interface HQLStepView ()@property (nonatomic, copy) NSArray *titlesArray;@property (nonatomic, assign) NSUInteger stepIndex;@property (nonatomic, strong) UIProgressView *progressView;@property (nonatomic, strong) NSMutableArray *circleViewArray;@property (nonatomic, strong) NSMutableArray *titleLabelArray;@property (nonatomic, strong) UILabel *indicatorLabel;@end@implementation HQLStepView#pragma mark - Init- (instancetype)initWithFrame:(CGRect)frame titlesArray:(NSArray *)titlesArray stepIndex:(NSUInteger)stepIndex { self = [super initWithFrame:frame]; if (self) { _titlesArray = [titlesArray copy]; _stepIndex = stepIndex; // 進(jìn)度條 [self addSubview:self.progressView];  for (NSString *title in _titlesArray) {    // 圓圈  UIView *circle = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 13, 13)];  circle.backgroundColor = [UIColor lightGrayColor];  circle.layer.cornerRadius = 13.0f / 2;  [self addSubview:circle];  [self.circleViewArray addObject:circle];    // 標(biāo)題  UILabel *label = [[UILabel alloc] init];  label.text = title;  label.font = [UIFont systemFontOfSize:14];  label.textAlignment = NSTextAlignmentCenter;  [self addSubview:label];  [self.titleLabelArray addObject:label]; }  // 當(dāng)前索引數(shù)字 [self addSubview:self.indicatorLabel]; } return self;}// 布局更新頁(yè)面元素- (void)layoutSubviews { NSInteger perWidth = self.frame.size.width / self.titlesArray.count;  // 進(jìn)度條 self.progressView.frame = CGRectMake(0, 0, self.frame.size.width - perWidth, 1); self.progressView.center = CGPointMake(self.frame.size.width / 2, self.frame.size.height / 4);  CGFloat startX = self.progressView.frame.origin.x; for (int i = 0; i < self.titlesArray.count; i++) { // 圓圈 UIView *cycle = self.circleViewArray[i]; if (cycle) {  cycle.center = CGPointMake(i * perWidth + startX, self.progressView.center.y); }  // 標(biāo)題 UILabel *label = self.titleLabelArray[i]; if (label) {  label.frame = CGRectMake(perWidth * i, self.frame.size.height / 2, self.frame.size.width / self.titlesArray.count, self.frame.size.height / 2 ); } } self.stepIndex = self.stepIndex;}#pragma mark - Custom Accessors- (UIProgressView *)progressView { if (!_progressView) { _progressView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleDefault]; _progressView.progressTintColor = TINT_COLOR; _progressView.progress = self.stepIndex / ((self.titlesArray.count - 1) * 1.0); } return _progressView;}- (UILabel *)indicatorLabel { if (!_indicatorLabel) { _indicatorLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 23, 23)]; _indicatorLabel.textColor = TINT_COLOR; _indicatorLabel.textAlignment = NSTextAlignmentCenter; _indicatorLabel.backgroundColor = [UIColor whiteColor]; _indicatorLabel.layer.cornerRadius = 23.0f / 2; _indicatorLabel.layer.borderColor = [TINT_COLOR CGColor]; _indicatorLabel.layer.borderWidth = 1; _indicatorLabel.layer.masksToBounds = YES; } return _indicatorLabel;}- (NSMutableArray *)circleViewArray { if (!_circleViewArray) { _circleViewArray = [[NSMutableArray alloc] initWithCapacity:self.titlesArray.count]; } return _circleViewArray;}- (NSMutableArray *)titleLabelArray { if (!_titleLabelArray) { _titleLabelArray = [[NSMutableArray alloc] initWithCapacity:self.titlesArray.count]; } return _titleLabelArray;}// 設(shè)置當(dāng)前進(jìn)度索引,更新圓形圖片、文本顏色、當(dāng)前索引數(shù)字- (void)setStepIndex:(NSUInteger)stepIndex { for (int i = 0; i < self.titlesArray.count; i++) { UIView *cycle = self.circleViewArray[i]; UILabel *label = self.titleLabelArray[i]; if (stepIndex >= i) {  cycle.backgroundColor = TINT_COLOR;  label.textColor = TINT_COLOR; } else {  cycle.backgroundColor = [UIColor lightGrayColor];  label.textColor = [UIColor lightGrayColor]; } }}#pragma mark - Public- (void)setStepIndex:(NSUInteger)stepIndex animation:(BOOL)animation { if (stepIndex < self.titlesArray.count) { // 更新顏色 self.stepIndex = stepIndex; // 設(shè)置進(jìn)度條 [self.progressView setProgress:stepIndex / ((self.titlesArray.count - 1) * 1.0) animated:animation]; // 設(shè)置當(dāng)前索引數(shù)字 self.indicatorLabel.text = [NSString stringWithFormat:@"%lu", stepIndex + 1]; self.indicatorLabel.center = ((UIView *)[self.circleViewArray objectAtIndex:stepIndex]).center; }}@end

接口調(diào)用:

- (void)viewDidLoad { [super viewDidLoad];  // 初始化 _hqlStepView = [[HQLStepView alloc] initWithFrame:CGRectMake(0, 200, self.view.frame.size.width, 60) titlesArray:@[@"第一步", @"第二步", @"第三步"] stepIndex:0]; [self.view addSubview:_hqlStepView];}- (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated];  // 設(shè)置當(dāng)前步驟,步驟索引=數(shù)組索引 [_hqlStepView setStepIndex:0 animation:YES];}

效果:

iOS,步驟,進(jìn)度條,例代碼

因?yàn)?UIProgressView 實(shí)現(xiàn)的水平進(jìn)度條高度值默認(rèn)為1,設(shè)置frame是無(wú)效的。可以通過(guò)仿射變換的方式增加它的高度。

第三方框架

參考:

總結(jié):

以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,如果有疑問(wèn)大家可以留言交流,謝謝大家對(duì)VEVB武林網(wǎng)的支持。


注:相關(guān)教程知識(shí)閱讀請(qǐng)移步到IOS開(kāi)發(fā)頻道。
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 在线观看免费污视频 | 国产亚洲精品久久久久久久久久 | 一区二区三区四区高清视频 | 亚洲人成中文字幕在线观看 | 欧美精品一区二区三区四区 | 青青国产在线视频 | 久久吊 | 1314成人网 | 国产亚洲福利 | 国产一级淫片a级aaa | www嫩草| 在线播放免费av | 精品一区二区久久久久久按摩 | 国产又粗又爽又深的免费视频 | 视屏一区 | 日日操夜 | 欧美18一19sex性护士农村 | 日本欧美一区二区三区视频麻豆 | 欧美日韩免费在线观看视频 | av影院在线播放 | 亚洲一区二区三区视频免费 | 亚洲国产精品二区 | 国产一区二区在线观看视频 | 黄污污网站 | 久久久青 | 久久久久久久一区二区 | 男女牲高爱潮免费视频男女 | 欧美a久久 | 一本色道久久综合狠狠躁篇适合什么人看 | 久草在线最新免费 | 一区二区网 | 91成人一区 | 美女羞羞视频在线观看 | 中文字幕涩涩久久乱小说 | 久久精品亚洲一区 | 4p一女两男做爰在线观看 | 悠悠成人资源亚洲一区二区 | 激情av在线 | 日本精品一区二区 | 国产一级做a爱片在线看免 2019天天干夜夜操 | 麻豆视频国产在线观看 |