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