zoukankan      html  css  js  c++  java
  • 自定义的进度条

    /** 初始化一个progress,
     aFrame                    外层的大小
     aFrameColor         外层的颜色
     aBarColor               里层的颜色
     gapSize                   里层和外层的间隙
     **/
    
    - (id)initWithFrame:(CGRect)aFrame frameColor:(UIColor *)aFrameColor barColor:(UIColor *)aBarColor aFrameCornerRadius:(CGFloat)aFrameCornerRadius aFrameBorderColor:(CGColorRef)aFrameBorderColor gapSize:(CGFloat)gapSize
    {
        self = [super initWithFrame:aFrame];
        if (self) {
            self.backgroundColor = [UIColor clearColor];
            _gap = gapSize;
            
            _outter = [[UILabel alloc]init];
            _outter.frame = self.bounds;
            _outter.backgroundColor = aFrameColor;
            _outter.layer.borderWidth = 1;
            _outter.layer.borderColor = aFrameBorderColor;
            [self addSubview:_outter];
            
            _inner = [[UILabel alloc]init];
            _inner.frame = CGRectZero;
            _inner.backgroundColor = aBarColor;
            [self addSubview:_inner];
            
            _inner.layer.cornerRadius = aFrameCornerRadius - gapSize;
            _inner.layer.masksToBounds = YES;
            _outter.layer.cornerRadius = aFrameCornerRadius;
            _outter.layer.masksToBounds = YES;
        }
        return self;
    }
    
    
    - (void)setProgress:(float)progress
    {
        progress = progress<0?0:progress;
        progress = progress>1?1:progress;
        _inner.frame = CGRectMake(_gap, _gap, progress*(self.frame.size.width - _gap*2.0), self.frame.size.height - _gap *2.0);
    }
    
    - (void)dealloc
    {
        [_inner removeFromSuperview];
        [_outter removeFromSuperview];
    }
  • 相关阅读:
    ReentrantLock-公平锁、非公平锁、互斥锁、自旋锁
    行动的阻碍
    AQS-等待队列
    AQS-volatile、CAS
    UML类图符号
    最小堆
    红黑树
    Java面试题-Collection框架
    Java面试题-Java特性
    Qt QString中文 char* UTF-8 QByteArray QTextCodec unicode gb2312 GBK 乱码和转码问题
  • 原文地址:https://www.cnblogs.com/cityingma/p/5390535.html
Copyright © 2011-2022 走看看