新项目要做入驻功能,其中包括一个入住流程,类似登录或者注册流程如下图。

之前想着用自己绘图来做,可是又懒不想多写代码,所以就想着能不能用进度条来做。

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 <UIKit/UIKit.h>

@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"

;

@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(, , frame.size.width, )];
    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);
    ; i<titleArray.count; i++) {
         //图片按钮
        UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];
        [btn setImage:[UIImage imageNamed:@"0.png"] forState:UIControlStateNormal];
        [btn setImage:[UIImage imageNamed:@"1.png"] forState:UIControlStateSelected];
        btn.frame=CGRectMake(_btnWidth/+_btnWidth*i-imgBtnWidth/, , imgBtnWidth, imgBtnWidth);
        btn.selected=YES;

        [stepProgressView addSubview:btn];
        [stepProgressView.imgBtnArray addObject:btn];

        //文字
        UILabel *titleLabel=[[UILabel alloc]initWithFrame:CGRectMake(btn.center.x-_btnWidth/, frame.size.height-, _btnWidth, )];
        titleLabel.text=[titleArray objectAtIndex:i];
        [titleLabel setTextColor:[UIColor blackColor]];
        titleLabel.textAlignment=NSTextAlignmentCenter;
        titleLabel.font=[UIFont systemFontOfSize:];
        [stepProgressView addSubview:titleLabel];
    }
    stepProgressView.stepIndex=-;
    return stepProgressView;

}
-(void)setStepIndex:(NSInteger)stepIndex
{
//  默认为-1 小于-1为-1 大于总数为总数
    _stepIndex=stepIndex<-?-:stepIndex;
    _stepIndex=stepIndex >=_imgBtnArray.count-?_imgBtnArray.count-:stepIndex;
    float _btnWidth=self.bounds.size.width/(_imgBtnArray.count);
    ; i<_imgBtnArray.count; i++) {
        UIButton *btn=[_imgBtnArray objectAtIndex:i];
        if (i<=_stepIndex) {
           btn.selected=YES;
        }
        else{
            btn.selected=NO;
        }
    }
    ) {
        self.progressView.progress=0.0;
    }
    )
    {
        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(, , self.view.bounds.size.width, ) withTitleArray:arr];
    stepView.stepIndex=;
    [self.view addSubview:stepView];

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

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

iOS 自定义步骤进度条的更多相关文章

  1. Xamarin iOS教程之进度条和滚动视图

    Xamarin iOS教程之进度条和滚动视图 Xamarin iOS 进度条 进度条可以看到每一项任务现在的状态.例如在下载的应用程序中有进度条,用户可以很方便的看到当前程序下载了多少,还剩下多少.Q ...

  2. 自定义环形进度条RoundProgressBar

    一.效果图: Canvas画圆环说明: 圆环宽度不必在意,只是画笔宽度设置后达到的效果. 二.实现步骤 1.自定义View-RoundProgressBar 2.设置属性resources(decle ...

  3. 步骤进度条 css

    用css写一个简单的步骤进度条 html代码: <h4>南京游玩</h4> <ul class="step-list"> <li> ...

  4. Android 自定义水平进度条的圆角进度

    有时项目中需要实现水平圆角进度,如下两种,其实很简单     下面开始看代码,先从主界面布局开始看起: <?xml version="1.0" encoding=" ...

  5. iOS开发:代码通用性以及其规范 第一篇(附带,自定义UITextView\进度条\双表显示\瀑布流 代码设计思路)

    在iOS团队开发中,我见过一些人的代码,也修改过他们的代码.有的人的代码写的非常之规范.通用,几乎不用交流,就可以知道如何修改以及在它基础上扩展延生.有的人的代码写的很垃圾,一眼看过去,简直会怀疑自己 ...

  6. 自定义带进度条的WebView , 增加获取web标题和url 回掉

    1.自定义ProgressWebView package com.app.android05; import android.content.Context; import android.graph ...

  7. 【Android 应用开发】 自定义 圆形进度条 组件

    转载著名出处 : http://blog.csdn.net/shulianghan/article/details/40351487 代码下载 : -- CSDN 下载地址 : http://down ...

  8. ProgressBar学习笔记,自定义横向进度条的样式(包含ActionBar上面的进度条)

     点显示进度条后→   android:max="100" 进度条的最大值 android:progress  进度条已经完成的进度值 android:progressDrawab ...

  9. android新闻项目、饮食助手、下拉刷新、自定义View进度条、ReactNative阅读器等源码

    Android精选源码 Android仿照36Kr官方新闻项目课程源码 一个优雅美观的下拉刷新布局,众多样式可选 安卓版本的VegaScroll滚动布局 android物流详情的弹框 健身饮食记录助手 ...

随机推荐

  1. WebLogic 两处任意文件上传漏洞动态分析(CVE-2018-2894)

    0x01 前言 CNCERT前几天发公告称发现Oracle公司出品的基于JavaEE结构的中间件WebLogic产品存在一个远程上传漏洞,并得到了厂商的确认,危害程度评分高达9.8分.鉴于厂商已进行了 ...

  2. (zxing.net)二维码Data Matrix的简介、实现与解码

    一.简介 Data Matrix 二维条码原名Datacode,由美国国际资料公司(International Data Matrix, 简称ID Matrix)于1989年发明.Data-Matri ...

  3. HTML5 LocalStorage Demo

    <!DOCTYPE html> <html lang="en" xmlns="http://www.w3.org/1999/xhtml"> ...

  4. django系列5.2--ORM数据库的单表操作

    单表操作 在views.py中添加对数据库的操作语句 #在逻辑代码中导入你要操作的表 from app import models def add_book(request): ''' 添加表记录 : ...

  5. [arc079f] Namori Grundy 分类讨论

    Description 给给全有一个NN个点NN条边的有向图,点的的编号从11到NN 给给全的图有NN条边,形如:(p1,1),(p2,2),...,(pN,N)(p1,1),(p2,2),...,( ...

  6. Python 各种编码相互转化 (目前只有Unicode utf-8)

    f='\u53eb\u6211' print f print(f.decode('unicode-escape'))

  7. scrapy 中用selector来提取数据的用法

      一. 基本概念 1. Selector是一个可独立使用的模块,我们可以用Selector类来构建一个选择器对象,然后调用它的相关方法如xpaht(), css()等来提取数据,如下 from sc ...

  8. linux中python配置tab=4个空格,并显示行号。

    vim ~/.vimrc 写入: set ts=4 set nu :wq 保存. source ~/.vimrc 使之生效.

  9. Windows系统下如何在cmd命令窗口中切换Python2.7和Python3.6

    针对在同一系统下我们可能安装多个版本的Python,毕竟Python2.7与Python3.6还是有不同的需求,但是在用Cmd命令窗口是我们可能默认的系统变量环境是其中一个版本,当我们需要在cmd命令 ...

  10. Spring注解大全,汇总版

    Spring使用的注解大全和解释 注解 解释 @Controller 组合注解(组合了@Component注解),应用在MVC层(控制层),DispatcherServlet会自动扫描注解了此注解的类 ...