[摘要]本文是對自定義的進度條的講解,對學習IOS蘋果軟件開發有所幫助,與大家分享。
/** 初始化一個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];
}