iOS如何實現步驟進度條功能-創新互聯

這篇文章主要介紹了iOS如何實現步驟進度條功能,具有一定借鑒價值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。

創新互聯公司2013年成立,是專業互聯網技術服務公司,擁有項目網站建設、成都網站制作網站策劃,項目實施與項目整合能力。我們以讓每一個夢想脫穎而出為使命,1280元祁連做網站,已為上家服務,為祁連各地企業和個人服務,聯系電話:18980820575

源碼

將步驟進度條封裝成一個 HQLStepView 類,它是 UIView 的子類。

HQLStepView.h 文件

#import <UIKit/UIKit.h>@interface HQLStepView : UIView// 指定初始化方法- (instancetype)initWithFrame:(CGRect)frame titlesArray:(NSArray *)titlesArray stepIndex:(NSUInteger)stepIndex;// 設置當前步驟- (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; // 進度條 [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];  // 標題  UILabel *label = [[UILabel alloc] init];  label.text = title;  label.font = [UIFont systemFontOfSize:14];  label.textAlignment = NSTextAlignmentCenter;  [self addSubview:label];  [self.titleLabelArray addObject:label]; } // 當前索引數字 [self addSubview:self.indicatorLabel]; } return self;}// 布局更新頁面元素- (void)layoutSubviews { NSInteger perWidth = self.frame.size.width / self.titlesArray.count; // 進度條 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); } // 標題 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;}// 設置當前進度索引,更新圓形圖片、文本顏色、當前索引數字- (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; // 設置進度條 [self.progressView setProgress:stepIndex / ((self.titlesArray.count - 1) * 1.0) animated:animation]; // 設置當前索引數字 self.indicatorLabel.text = [NSString stringWithFormat:@"%lu", stepIndex + 1]; self.indicatorLabel.center = ((UIView *)[self.circleViewArray objectAtIndex:stepIndex]).center; }}@end

接口調用:

- (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]; // 設置當前步驟,步驟索引=數組索引 [_hqlStepView setStepIndex:0 animation:YES];}

感謝你能夠認真閱讀完這篇文章,希望小編分享的“iOS如何實現步驟進度條功能”這篇文章對大家有幫助,同時也希望大家多多支持創新互聯網站建設公司,,關注創新互聯行業資訊頻道,更多相關知識等著你來學習!

當前文章:iOS如何實現步驟進度條功能-創新互聯
本文URL:http://m.kartarina.com/article6/cddhog.html

成都網站建設公司_創新互聯,為您提供ChatGPT關鍵詞優化品牌網站設計外貿網站建設自適應網站電子商務

廣告

聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯

成都定制網站建設
主站蜘蛛池模板: 亚洲AV无码成人精品区日韩| 亚洲午夜无码久久久久小说 | 东京热av人妻无码专区| av无码a在线观看| 久久亚洲精品成人av无码网站| 久久精品无码中文字幕| 无码精品A∨在线观看中文| 无码无套少妇毛多69XXX| 一本一道av中文字幕无码| 无码中文字幕av免费放| 久久久久亚洲AV片无码| 午夜无码中文字幕在线播放| 99久久亚洲精品无码毛片| 国内精品人妻无码久久久影院导航 | 亚洲av无码专区国产不乱码| 国产午夜无码精品免费看| 无码人妻丰满熟妇区毛片| 国产成人无码AV麻豆| 少妇伦子伦精品无码STYLES| 国产成人AV无码精品| 国产成年无码久久久久下载| 无码专区人妻系列日韩精品少妇 | 亚洲av日韩av永久无码电影 | 亚洲成a人无码亚洲成av无码| 国产办公室秘书无码精品99| 中文字幕无码av激情不卡久久| 成年男人裸j照无遮挡无码| 亚洲国产精品无码观看久久| 蜜桃成人无码区免费视频网站 | 无码人妻丰满熟妇区免费| 国产精品亚洲аv无码播放| 精品无人区无码乱码毛片国产| 无码专区一va亚洲v专区在线| 免费无遮挡无码视频网站| 本道久久综合无码中文字幕| 国产精品爆乳奶水无码视频| 精品久久久久久无码人妻| 少妇人妻偷人精品无码AV| 亚无码乱人伦一区二区| 亚洲国产成人精品无码久久久久久综合 | 亚洲熟妇无码乱子AV电影|