123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- //
- // GGProgressView.m
- //
- // Created by GG on 2016/10/20.
- // Copyright © 2016年 GG. All rights reserved.
- //
- #import "GGProgressView.h"
- @interface GGProgressView()
- {
- // UIView *_progressView;
- float _progress;
- }
- @end
- @implementation GGProgressView
- -(instancetype)initWithFrame:(CGRect)frame{
- if (self=[super initWithFrame:frame]) {
- // _progressView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, frame.size.height)];
- _progress=0;
- // self.progressViewStyle=style;
- // [self addSubview:_progressView];
- }
- return self;
- // return [self initWithFrame:frame progressViewStyle:GGProgressViewStyleDefault];
- }
- //
- //- (instancetype)initWithFrame:(CGRect)frame progressViewStyle:(GGProgressViewStyle)style
- //{
- // if (self=[super initWithFrame:frame]) {
- //// _progressView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, frame.size.height)];
- // _progress=0;
- // self.progressViewStyle=style;
- //// [self addSubview:_progressView];
- // }
- // return self;
- //}
- //-(void)setProgressViewStyle:(GGProgressViewStyle)progressViewStyle
- //{
- // _progressViewStyle=progressViewStyle;
- // if (progressViewStyle==GGProgressViewStyleTrackFillet) {
- // self.layer.masksToBounds=YES;
- // self.layer.cornerRadius=self.bounds.size.height/2;
- // }
- // else if (progressViewStyle==GGProgressViewStyleAllFillet)
- // {
- // self.layer.masksToBounds=YES;
- // self.layer.cornerRadius=self.bounds.size.height/2;
- //// _progressView.layer.cornerRadius=self.bounds.size.height/2;
- // }
- //}
- -(void)setTrackTintColor:(UIColor *)trackTintColor{
- _trackTintColor=trackTintColor;
- [self setNeedsDisplay];
- // if (self.trackImage) {
- //
- // }
- // else
- // {
- // self.backgroundColor=trackTintColor;
- // }
- }
- -(void)setProgress:(float)progress
- {
- _progress=MIN(progress, 1);
- // _progressView.frame=CGRectMake(0, 0, self.bounds.size.width*_progress, self.bounds.size.height);
- [self setNeedsDisplay];
- }
- -(float)progress
- {
- return _progress;
- }
- -(void)setProgressTintColor:(UIColor *)progressTintColor{
- _progressTintColor = progressTintColor;
- [self setNeedsDisplay];
- // _progressView.backgroundColor=progressTintColor;
- }
- //-(void)setTrackImage:(UIImage *)trackImage
- //{
- // _trackImage=trackImage;
- // if(self.isTile)
- // {
- // self.backgroundColor=[UIColor colorWithPatternImage:trackImage];
- // }
- // else
- // {
- // self.backgroundColor=[UIColor colorWithPatternImage:[self stretchableWithImage:trackImage]];
- // }
- //}
- //-(void)setIsTile:(BOOL)isTile
- //{
- // _isTile = isTile;
- // if (self.progressImage) {
- // [self setProgressImage:self.progressImage];
- // }
- // if (self.trackImage) {
- // [self setTrackImage:self.trackImage];
- // }
- //}
- //-(void)setProgressImage:(UIImage *)progressImage
- //{
- // _progressImage = progressImage;
- // if(self.isTile)
- // {
- // _progressView.backgroundColor=[UIColor colorWithPatternImage:progressImage];
- // }
- // else
- // {
- // _progressView.backgroundColor=[UIColor colorWithPatternImage:[self stretchableWithImage:progressImage]];
- // }
- //}
- //- (UIImage *)stretchableWithImage:(UIImage *)image{
- // UIGraphicsBeginImageContextWithOptions(self.frame.size, NO, 0.f);
- // [image drawInRect:self.bounds];
- // UIImage *lastImage = UIGraphicsGetImageFromCurrentImageContext();
- // UIGraphicsEndImageContext();
- // return lastImage;
- //}
- - (void)drawRect:(CGRect)rect {
- CGFloat width = self.bounds.size.width*_progress;
- [self.progressTintColor set]; //设置线条颜色
- {
- UIBezierPath* path = [UIBezierPath bezierPath];
- path.lineWidth = 1.0;
- path.lineCapStyle = kCGLineCapRound; //线条拐角
- path.lineJoinStyle = kCGLineJoinRound; //终点处理
- [path moveToPoint:CGPointMake(width - 9.5f + 19.0f * 0.8f, 0.0f)];//起点
- // Draw the lines
- [path addLineToPoint:CGPointMake(width - 9.5f + 19.0f * 0.2f, self.mj_h)];
- [path addLineToPoint:CGPointMake(0.0f, self.mj_h)];
- [path addLineToPoint:CGPointMake(0.0f, 0.0f)];
- [path closePath];//第五条线通过调用closePath方法得到的
- [path fill];//颜色填充
- }
-
- [self.trackTintColor set];
- {
- UIBezierPath* path = [UIBezierPath bezierPath];
- path.lineWidth = 1.0;
- path.lineCapStyle = kCGLineCapRound; //线条拐角
- path.lineJoinStyle = kCGLineJoinRound; //终点处理
- [path moveToPoint:CGPointMake(width - 9.5f + 19.0f * 0.8f, 0.0f)];//起点
- // Draw the lines
- [path addLineToPoint:CGPointMake(self.mj_w, 0.0f)];
- [path addLineToPoint:CGPointMake(self.mj_w, self.mj_h)];
- [path addLineToPoint:CGPointMake(width - 9.5f + 19.0f * 0.2f, self.mj_h)];
- [path closePath];//第五条线通过调用closePath方法得到的
- [path fill];//颜色填充
- }
- }
- @end
|