Initial commit
This commit is contained in:
@@ -0,0 +1,128 @@
|
||||
//
|
||||
// IfishDengjiProgress.m
|
||||
// CollectionViewTest
|
||||
//
|
||||
// Created by imac on 17/2/28.
|
||||
// Copyright © 2017年 xiang. All rights reserved.
|
||||
//
|
||||
|
||||
#import "IfishDengjiProgress.h"
|
||||
|
||||
static const CGFloat kProgressViewPonitMinH = 10.0f;
|
||||
static const CGFloat kProgressViewPonitW = 10.0f;
|
||||
|
||||
@interface IfishDengjiProgress ()
|
||||
|
||||
@property (nonatomic, strong) UIView *gressView;
|
||||
@property (nonatomic, strong) UIView *pointView;
|
||||
@property (nonatomic, strong) UIView *trackView;
|
||||
|
||||
@end
|
||||
//试图最小高度不要小于十
|
||||
@implementation IfishDengjiProgress
|
||||
|
||||
- (instancetype)initWithFrame:(CGRect)frame
|
||||
{
|
||||
self = [super initWithFrame:frame];
|
||||
if (self) {
|
||||
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
-(UIView*)gressView
|
||||
{
|
||||
if (!_gressView) {
|
||||
_gressView = [[UIView alloc] initWithFrame:CGRectMake(0,0,0, self.frame.size.height)];
|
||||
_gressView.backgroundColor = self.progressColor;
|
||||
[self addSubview:_gressView];
|
||||
}
|
||||
return _gressView;
|
||||
}
|
||||
|
||||
-(UIView*)pointView{
|
||||
|
||||
if (!_pointView) {
|
||||
|
||||
_pointView = [[UIView alloc] initWithFrame:CGRectMake(CGRectGetMaxX(self.gressView.frame)- kProgressViewPonitW, 0, kProgressViewPonitW, self.frame.size.height)];
|
||||
_pointView.layer.masksToBounds = YES;
|
||||
CGFloat ViewW = self.frame.size.height - kProgressViewPonitMinH;
|
||||
_pointView.layer.cornerRadius = ViewW/2;
|
||||
|
||||
_pointView.backgroundColor = self.pointColor;
|
||||
[self addSubview:_pointView];
|
||||
|
||||
}
|
||||
|
||||
return _pointView;
|
||||
}
|
||||
|
||||
-(UIView *)trackView{
|
||||
if (!_trackView) {
|
||||
|
||||
_trackView = [[UIView alloc] initWithFrame:CGRectMake(CGRectGetMaxX(self.gressView.frame), CGRectGetMinY(self.gressView.frame), 0, self.frame.size.height)];
|
||||
_trackView.backgroundColor = self.trackColor;
|
||||
[self addSubview:_trackView];
|
||||
}
|
||||
|
||||
return _trackView;
|
||||
}
|
||||
|
||||
|
||||
- (void)setProgress:(float)progress
|
||||
{
|
||||
if (progress >= 1.0) {
|
||||
_progress = 1.0;
|
||||
}
|
||||
else if (progress <= 0) {
|
||||
_progress = 0.0;
|
||||
}
|
||||
else {
|
||||
_progress = progress;
|
||||
}
|
||||
|
||||
_gressView.frame = CGRectMake(0, 0, _progress * self.frame.size.width, self.frame.size.height);
|
||||
}
|
||||
|
||||
- (void)setProgressColor:(UIColor *)progressColor
|
||||
{
|
||||
_progressColor = progressColor;
|
||||
|
||||
_gressView.backgroundColor = progressColor;
|
||||
}
|
||||
|
||||
- (void)layoutSubviews
|
||||
{
|
||||
[super layoutSubviews];
|
||||
|
||||
CGFloat ViewH = self.frame.size.height - kProgressViewPonitMinH;
|
||||
if (ViewH<0) {
|
||||
//此时不显示圆点
|
||||
ViewH = self.frame.size.height;
|
||||
}
|
||||
CGFloat oriY = self.frame.size.height/2 - ViewH/2;
|
||||
self.gressView.frame = CGRectMake(0,oriY, _progress * self.frame.size.width, ViewH);
|
||||
CGFloat poitH= self.frame.size.height - 4;
|
||||
self.pointView.frame = CGRectMake(CGRectGetMaxX(self.gressView.frame)- ViewH,self.frame.size.height/2 - poitH/2, ViewH, poitH);
|
||||
|
||||
self.trackView.frame = CGRectMake(CGRectGetMaxX(self.gressView.frame), CGRectGetMinY(self.gressView.frame),(1-_progress) * self.frame.size.width, ViewH);
|
||||
if (_progress==0||_progress ==1) {
|
||||
self.pointView.hidden = YES;
|
||||
}else{
|
||||
self.pointView.hidden = NO;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
// Only override drawRect: if you perform custom drawing.
|
||||
// An empty implementation adversely affects performance during animation.
|
||||
- (void)drawRect:(CGRect)rect {
|
||||
// Drawing code
|
||||
}
|
||||
*/
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user