国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

服務(wù)器之家:專注于服務(wù)器技術(shù)及軟件下載分享
分類導(dǎo)航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術(shù)|正則表達(dá)式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務(wù)器之家 - 編程語言 - IOS - iOS實(shí)現(xiàn)步驟進(jìn)度條功能實(shí)例代碼

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

2021-05-17 16:35獨(dú)木舟的木 IOS

這篇文章主要給大家介紹了關(guān)于iOS實(shí)現(xiàn)步驟進(jìn)度條功能的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

前言

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

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

ios uikit 框架中并沒有提供類似的控件,我們可以使用 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 文件

?
1
2
3
4
5
6
7
8
9
10
11
#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 文件

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#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;
}
 
// 布局更新頁面元素
- (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)用:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
- (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實(shí)現(xiàn)步驟進(jìn)度條功能實(shí)例代碼

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

第三方框架

參考:

總結(jié):

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

原文鏈接:https://www.jianshu.com/p/fb471ca68a1b

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 欧美日韩不卡合集视频 | 欧美激情一区二区三级高清视频 | 成人乱人乱一区二区三区 | 成人av影视 | 亚洲精品乱码久久久久久按摩观 | 久久精品亚洲精品 | 亚洲国产精品久久人人爱 | 亚洲国产精品免费在线观看 | 日韩成人高清视频 | 日韩av资源网 | 中文字幕在线观看视频地址二 | 亚洲国产精品久久久 | 欧美国产日韩在线 | 国产中文字幕在线观看 | 欧美精品一区二区三区一线天视频 | 中文av字幕 | 精品一区二区久久久久久久网站 | 日韩中文在线视频 | 欧美日韩国产一级片 | 久久人人爽人人爽人人片亚洲 | 人人爽人人爽人人片av | 在线观看国产成人av片 | 久久xx | 色站综合 | 国产精品自拍系列 | 91视频.www| 黄色毛片在线看 | 欧美日韩一区二区三区在线观看 | 精品欧美一区二区三区久久久 | 国内精品一区二区 | 中文在线视频 | 久久精品久久久 | 日韩在线看片 | 亚洲毛片在线观看 | 日韩精品在线观看视频 | 日韩欧美国产一区二区三区 | 欧美视频在线播放 | 欧日韩在线视频 | 成人午夜在线 | 久久久久久成人 | 麻豆国产免费 |