最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

iOS如何自定義步驟進(jìn)度條實(shí)例詳解

 更新時間:2018年11月07日 09:33:14   作者:小崔的筆記本  
這篇文章主要給大家介紹了關(guān)于iOS如何自定義步驟進(jìn)度條的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

前言

最近新項(xiàng)目要做入駐功能,其中包括一個入住流程,類似登錄或者注冊流程如下圖。

之前想著用自己繪圖來做,可是又懶不想多寫代碼,所以就想著能不能用進(jìn)度條來做。

實(shí)現(xiàn)方法如下:

1.用進(jìn)度條做的首先要解決的是進(jìn)度條的高度問題,可以通過仿射變換來擴(kuò)大高度。

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

2.用進(jìn)度條要設(shè)置進(jìn)度progress要與按鈕對應(yīng)

通過步驟的索引來改變進(jìn)度的值和按鈕的圖片。由于按鈕的左右有間隔所以要注意-1、0和最后一個的progress值。

3.擴(kuò)展

看有一些類似查公交、車站運(yùn)行的APP有的可以點(diǎn)擊站點(diǎn),所以就用按鈕來做,這樣可以擴(kuò)展。

 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"

static const float imgBtnWidth=18;

@interface StepProgressView ()

@property (nonatomic,strong) UIProgressView *progressView;

//用UIButton防止以后有點(diǎn)擊事件
@property (nonatomic,strong) NSMutableArray *imgBtnArray;

@end

@implementation StepProgressView

+(instancetype)progressViewFrame:(CGRect)frame withTitleArray:(NSArray *)titleArray
{
 StepProgressView *stepProgressView=[[StepProgressView alloc]initWithFrame:frame];
 //進(jìn)度條
 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<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/2+_btnWidth*i-imgBtnWidth/2, 0, imgBtnWidth, imgBtnWidth);
 btn.selected=YES;
 
 [stepProgressView addSubview:btn];
 [stepProgressView.imgBtnArray addObject:btn];
 
 //文字
 UILabel *titleLabel=[[UILabel alloc]initWithFrame:CGRectMake(btn.center.x-_btnWidth/2, frame.size.height-20, _btnWidth, 20)];
 titleLabel.text=[titleArray objectAtIndex:i];
 [titleLabel setTextColor:[UIColor blackColor]];
 titleLabel.textAlignment=NSTextAlignmentCenter;
 titleLabel.font=[UIFont systemFontOfSize:18];
 [stepProgressView addSubview:titleLabel];
 }
 stepProgressView.stepIndex=-1;
 return stepProgressView;
 
}
-(void)setStepIndex:(NSInteger)stepIndex
{
// 默認(rèn)為-1 小于-1為-1 大于總數(shù)為總數(shù)
 _stepIndex=stepIndex<-1?-1:stepIndex;
 _stepIndex=stepIndex >=_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=@[@"區(qū)寶時尚",@"區(qū)寶時尚",@"時尚",@"區(qū)寶時尚",@"時尚"];
 StepProgressView *stepView=[StepProgressView progressViewFrame:CGRectMake(0, 100, self.view.bounds.size.width, 60) withTitleArray:arr];
 stepView.stepIndex=2;
 [self.view addSubview:stepView];

 補(bǔ)充:上面的代碼有一個bug,例如stepIndex=-1時,_stepIndex=并不等-1,原來數(shù)組的count返回的是NSUInteger而stepIndex是NSInteger類型,所以需要強(qiáng)制轉(zhuǎn)換一下

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

總結(jié):

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

相關(guān)文章

  • Objective-C實(shí)現(xiàn)無限循環(huán)輪播器

    Objective-C實(shí)現(xiàn)無限循環(huán)輪播器

    這篇文章主要介紹了Objective-C實(shí)現(xiàn)無限循環(huán)輪播器的相關(guān)資料,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-05-05
  • iOS tableView多輸入框如何獲取數(shù)據(jù)

    iOS tableView多輸入框如何獲取數(shù)據(jù)

    這篇文章主要給大家介紹了關(guān)于iOS tableView多輸入框如何獲取數(shù)據(jù)的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-04-04
  • iOS中的UITextView文字輸入光標(biāo)使用技巧小結(jié)

    iOS中的UITextView文字輸入光標(biāo)使用技巧小結(jié)

    UITextView在用戶體驗(yàn)方面有著十分明顯的作用,包括鍵盤的呼出及文字的選擇等,接下來就來整理給出一份iOS中的UITextView文字輸入光標(biāo)使用技巧小結(jié),需要的朋友可以參考下
    2016-05-05
  • iOS開發(fā)實(shí)現(xiàn)下載器的基本功能(1)

    iOS開發(fā)實(shí)現(xiàn)下載器的基本功能(1)

    這篇文章主要為大家詳細(xì)介紹了iOS開發(fā)實(shí)現(xiàn)下載器基本功能的相關(guān)資料,感興趣的小伙伴們可以參考一下
    2016-07-07
  • iOS實(shí)現(xiàn)數(shù)字倍數(shù)動畫效果

    iOS實(shí)現(xiàn)數(shù)字倍數(shù)動畫效果

    在iOS開發(fā)中,制作動畫效果是最讓開發(fā)者享受的環(huán)節(jié)之一,下面這篇文章主要給大家介紹了關(guān)于iOS實(shí)現(xiàn)數(shù)字倍數(shù)動畫效果的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-02-02
  • iOS仿熱門話題熱點(diǎn)輪播界面tableView

    iOS仿熱門話題熱點(diǎn)輪播界面tableView

    這篇文章主要為大家詳細(xì)介紹了iOS仿熱門話題熱點(diǎn)輪播界面tableView,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-09-09
  • 詳解iOS應(yīng)用開發(fā)中Core Data數(shù)據(jù)存儲的使用

    詳解iOS應(yīng)用開發(fā)中Core Data數(shù)據(jù)存儲的使用

    這篇文章主要介紹了iOS應(yīng)用開發(fā)中Core Data數(shù)據(jù)存儲的使用,Core Data可以看作是一個內(nèi)嵌型數(shù)據(jù)庫SQLite的iOS專用版本,需要的朋友可以參考下
    2016-02-02
  • ios8 UITableView設(shè)置 setSeparatorInset UIEdgeInsetsZero不起作用的解決辦法(去掉15px空白間距)

    ios8 UITableView設(shè)置 setSeparatorInset UIEdgeInsetsZero不起作用的解決

    這篇文章主要介紹了ios8 UITableView設(shè)置 setSeparatorInset UIEdgeInsetsZero不起作用的解決辦法(去掉15px空白間距)的相關(guān)資料,需要的朋友可以參考下
    2016-02-02
  • iOS 12中無法獲取WiFi的SSID了?別慌看這里!

    iOS 12中無法獲取WiFi的SSID了?別慌看這里!

    這篇文章主要給大家介紹了關(guān)于iOS 12中無法獲取WiFi的SSID的相關(guān)資料,文中通過示例代碼以及圖文介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2018-09-09
  • iOS10 適配遠(yuǎn)程推送功能實(shí)現(xiàn)代碼

    iOS10 適配遠(yuǎn)程推送功能實(shí)現(xiàn)代碼

    這篇文章主要介紹了iOS10 適配遠(yuǎn)程推送功能實(shí)現(xiàn)代碼,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-09-09

最新評論

吴堡县| 双流县| 揭阳市| 达拉特旗| 临桂县| 墨玉县| 仙游县| 延川县| 阿城市| 定日县| 喀喇| 高平市| 卢龙县| 镇宁| 蒲城县| 百色市| 淅川县| 北海市| 武穴市| 洛宁县| 高青县| 南乐县| 保德县| 镇坪县| 罗田县| 安泽县| 富顺县| 和林格尔县| 无棣县| 安丘市| 舞钢市| 伊通| 长沙县| 武邑县| 师宗县| 含山县| 交城县| 保靖县| 高清| 永城市| 长顺县|