设为首页 加入收藏

TOP

自定义的进度条
2017-10-13 10:17:09 】 浏览:6235
Tags:定义 进度

/** 初始化一个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];
}

 

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇IOS Quartz2D简介 下一篇按钮在cell上的高亮状态出现的慢

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目