• 自定义UIProgressView


    自定义CustomporgressView

    #import <UIKit/UIKit.h>
    
    @interface CustomporgressView : UIView
    @property(nonatomic,assign)int step;
    //allCount一共几个节点  step当前节点
    -(instancetype)initWithFrame:(CGRect)frame withCount:(int)allCount withCurrentStep:(int)step;
    @end
    
    #import "CustomporgressView.h"
    
    #define TintColor [UIColor redColor]
    #define TrackTintColor [UIColor lightGrayColor]
    @interface CustomporgressView()
    //进度条
    @property(nonatomic,strong)UIProgressView *progressView;
    //当前指示器
    @property(nonatomic,strong)UILabel *indicatorLabel;
    //圆点数组
    @property(nonatomic,strong)NSMutableArray *mCircleArr;
    
    @end
    
    @implementation CustomporgressView
    
    -(instancetype)initWithFrame:(CGRect)frame withCount:(int)allCount withCurrentStep:(int)step{
        self = [super initWithFrame:frame];
        if(self){
            self.progressView = [[UIProgressView alloc]initWithFrame:CGRectMake(0, 0, frame.size.width*0.8, 0)];
            self.progressView.center = self.center;
            self.progressView.progressTintColor = TintColor;
            self.progressView.trackTintColor = TrackTintColor;
            [self addSubview:self.progressView];
            
            self.mCircleArr = [NSMutableArray array];
            float width = self.progressView.frame.size.width/(allCount-1);
            for(int i=0;i<allCount;i++){
                UIView *circleView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 12, 12)];
                circleView.center = CGPointMake(i * width,0);
                circleView.clipsToBounds = YES;
                circleView.layer.cornerRadius = 6.0f;
        
                [self.progressView addSubview:circleView];
                [self.mCircleArr addObject:circleView];
            }
            [self.progressView addSubview:self.indicatorLabel];
            self.step = step;
        }
        return self;
    }
    -(UILabel *)indicatorLabel{
        if(!_indicatorLabel){
            _indicatorLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 20, 20)];
            _indicatorLabel.textAlignment = NSTextAlignmentCenter;
            _indicatorLabel.textColor = TintColor;
            _indicatorLabel.layer.borderWidth = 1.0f;
            _indicatorLabel.layer.cornerRadius = 12;
             _indicatorLabel.layer.borderColor = TintColor.CGColor;
            _indicatorLabel.backgroundColor = [UIColor whiteColor];
        }
        return _indicatorLabel;
    }
    
    
    -(void)setStep:(int)step{
        //超过数组边界
        if(step >= self.mCircleArr.count){
            return;
        }
        _step = step;
        
        for(int i=0;i<self.mCircleArr.count;i++){
            UIView *circleView = self.mCircleArr[i];
            if(i < step){
                circleView.backgroundColor = TintColor;
            }else{
                circleView.backgroundColor = TrackTintColor;
            }
        }
        
        float width = self.progressView.frame.size.width/(self.mCircleArr.count-1);
        self.indicatorLabel.center = CGPointMake(width * step, 0);
        [ self.progressView setProgress:step*1.0/(self.mCircleArr.count-1)];
        _indicatorLabel.text = [NSString stringWithFormat:@"%d",step+1];
        
    }
    
    @end
    

     使用:

     CustomporgressView *customProgress = [[CustomporgressView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width-10, 50) withCount:5 withCurrentStep:2];
    [view addSubview:customProgress];
    
  • 相关阅读:
    mysql无法启动ERROR! MySQL is running but PID file could not be found ?
    mybatis返回list很智能很简答的,只需要配置resultmap进行类型转换,你dao方法直接写返回值list<对应的object>就行了啊
    mybatis resultmap标签type属性什么意思
    python学习笔记——第三章 串
    POJ 2485:Highways(最小生成树&amp;&amp;prim)
    G-Sensor 校准标准
    Unity3D 4.x 使用Mecanim实现动画控制
    quartz群调查调度机制和源代码分析
    什么是你的七个核心竞争力-弱点让你闪
    poj 3368 Frequent values(段树)
  • 原文地址:https://www.cnblogs.com/hualuoshuijia/p/9963190.html
Copyright © 2020-2023  润新知