RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
iOS中怎么自定义步骤进度条

iOS中怎么自定义步骤进度条,针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。

我们注重客户提出的每个要求,我们充分考虑每一个细节,我们积极的做好成都网站建设、做网站服务,我们努力开拓更好的视野,通过不懈的努力,创新互联赢得了业内的良好声誉,这一切,也不断的激励着我们更好的服务客户。 主要业务:网站建设,网站制作,网站设计,微信小程序,网站开发,技术开发实力,DIV+CSS,PHP及ASP,ASP.Net,SQL数据库的技术开发工程师。

实现方法如下:

1.用进度条做的首先要解决的是进度条的高度问题,可以通过仿射变换来扩大高度。

progressView.transform = CGAffineTransformMakeScale(1.0f,2.0f);

2.用进度条要设置进度progress要与按钮对应

通过步骤的索引来改变进度的值和按钮的图片。由于按钮的左右有间隔所以要注意-1、0和最后一个的progress值。

3.扩展

看有一些类似查公交、车站运行的APP有的可以点击站点,所以就用按钮来做,这样可以扩展。

4.代码

//// StepProgressView.h// CustomProgress//// Created by City--Online on 15/12/12.// Copyright © 2015年 City--Online. All rights reserved.//#import @interface StepProgressView : UIView@property (nonatomic,assign) NSInteger stepIndex;+(instancetype)progressViewFrame:(CGRect)frame withTitleArray:(NSArray *)titleArray;@end

//// StepProgressView.m// CustomProgress//// Created by City--Online on 15/12/12.// Copyright © 2015年 City--Online. All rights reserved.//#import "StepProgressView.h"static const float imgBtnWidth=18;@interface StepProgressView ()@property (nonatomic,strong) UIProgressView *progressView;//用UIButton防止以后有点击事件@property (nonatomic,strong) NSMutableArray *imgBtnArray;@end@implementation StepProgressView+(instancetype)progressViewFrame:(CGRect)frame withTitleArray:(NSArray *)titleArray{ StepProgressView *stepProgressView=[[StepProgressView alloc]initWithFrame:frame]; //进度条 stepProgressView.progressView=[[UIProgressView alloc]initWithFrame:CGRectMake(0, 5, frame.size.width, 10)]; stepProgressView.progressView.progressViewStyle=UIProgressViewStyleBar; stepProgressView.progressView.transform = CGAffineTransformMakeScale(1.0f,2.0f); stepProgressView.progressView.progressTintColor=[UIColor redColor]; stepProgressView.progressView.trackTintColor=[UIColor blueColor]; stepProgressView.progressView.progress=0.5; [stepProgressView addSubview:stepProgressView.progressView]; stepProgressView.imgBtnArray=[[NSMutableArray alloc]init]; float _btnWidth=frame.size.width/(titleArray.count); for (int i=0; i=_imgBtnArray.count-1?_imgBtnArray.count-1:stepIndex; float _btnWidth=self.bounds.size.width/(_imgBtnArray.count); for (int i=0; i<_imgBtnArray.count; i++) { UIButton *btn=[_imgBtnArray objectAtIndex:i]; if (i<=_stepIndex) {  btn.selected=YES; } else{  btn.selected=NO; } } if (_stepIndex==-1) { self.progressView.progress=0.0; } else if (_stepIndex==_imgBtnArray.count-1) { self.progressView.progress=1.0; } else { self.progressView.progress=(0.5+_stepIndex)*_btnWidth/self.frame.size.width; }}@end

5.使用和效果

NSArray *arr=@[@"区宝时尚",@"区宝时尚",@"时尚",@"区宝时尚",@"时尚"]; StepProgressView *stepView=[StepProgressView progressViewFrame:CGRectMake(0, 100, self.view.bounds.size.width, 60) withTitleArray:arr]; stepView.stepIndex=2; [self.view addSubview:stepView];

补充:上面的代码有一个bug,例如stepIndex=-1时,_stepIndex=并不等-1,原来数组的count返回的是NSUInteger而stepIndex是NSInteger类型,所以需要强制转换一下

stepIndex=stepIndex<-1?-1:stepIndex; _stepIndex = stepIndex >= (NSInteger)(_imgBtnArray.count-1) ? _imgBtnArray.count-1:stepIndex;

关于iOS中怎么自定义步骤进度条问题的解答就分享到这里了,希望以上内容可以对大家有一定的帮助,如果你还有很多疑惑没有解开,可以关注创新互联行业资讯频道了解更多相关知识。


分享标题:iOS中怎么自定义步骤进度条
标题链接:http://scyingshan.cn/article/ihppjg.html