Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release gzbj v1 #2

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Binary file modified .DS_Store
Binary file not shown.
60 changes: 0 additions & 60 deletions .gitignore

This file was deleted.

Binary file modified toone/.DS_Store
Binary file not shown.
Binary file removed toone/Classes/.DS_Store
Binary file not shown.
28 changes: 28 additions & 0 deletions toone/Classes/3rd/SGChart/SGBar.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// SGBar.h
// CAlayer
//
// Created by apple on 16/5/12.
// Copyright © 2016年 jzs.com. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface SGBar : UIView
/**
* 动画时间
*/
@property (assign,nonatomic) CGFloat totalTime;
/**
* 根据view的layer属性生成一个bar
*
* @param frame bar的frame
* @param percent 根据百分比显示bar的高度
* @param color bar的颜色
*
* @return 返回一个bar
*/
-(instancetype)initWithFrame:(CGRect)frame
percent:(CGFloat)percent
color:(UIColor*)color;
@end
74 changes: 74 additions & 0 deletions toone/Classes/3rd/SGChart/SGBar.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
//
// SGBar.m
// CAlayer
//
// Created by apple on 16/5/12.
// Copyright © 2016年 jzs.com. All rights reserved.
//

#import "SGBar.h"
#import "SGConst.h"

@implementation SGBar

-(CGFloat)totalTime{
if (!_totalTime) {
_totalTime = BAR_TOTALTIME;
}
return _totalTime;
}
-(instancetype)initWithFrame:(CGRect)frame
percent:(CGFloat)percent
color:(UIColor*)color{
self = [super initWithFrame:frame];
if (self) {
[self layer:percent withColor:color];
}
return self;
}
/**
* <#Description#>
*
* @param percent 根据百分比参数计算bar的高度
* @param color layer的颜色
*/
-(void)layer:(CGFloat)percent withColor:(UIColor*)color{

//起点
CGPoint startPoint = CGPointMake(self.frame.size.width/2, self.frame.size.height);

//终点
CGPoint endPoint = CGPointMake(self.frame.size.width/2, self.frame.size.height*(1-percent));
UIBezierPath * path = [UIBezierPath bezierPath];
[path moveToPoint:startPoint];
[path addLineToPoint:endPoint];

CAShapeLayer * layer = [CAShapeLayer layer];
layer.lineWidth = self.frame.size.width;
[self.layer addSublayer:layer];
layer.path = path.CGPath;
layer.strokeColor = color.CGColor ? :[UIColor redColor].CGColor;


CABasicAnimation *fillAnimation = [self animation:percent];
[layer addAnimation:fillAnimation forKey:nil];
}

#pragma mark - 动画
/**
* 填充动画过程
*
* @return CABasicAnimation
*/

- (CABasicAnimation *)animation:(CGFloat)percent{
CABasicAnimation *fillAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
fillAnimation.duration = BAR_TOTALTIME*percent;
fillAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
fillAnimation.fromValue = @0.0;
fillAnimation.toValue = @1.0;
fillAnimation.autoreverses = NO;
return fillAnimation;
}

@end
61 changes: 61 additions & 0 deletions toone/Classes/3rd/SGChart/SGBarChart.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
//
// SGBarChart.h
// bar自定义
//
// Created by apple on 16/5/13.
// Copyright © 2016年 jzs.com. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface SGBarChart : UIView

/**
* 重置数据
* datas和titleX需要调用show方法
*/
@property (nonatomic,retain) NSArray * datas;
@property (nonatomic,retain) NSArray * titleX;
@property (nonatomic,retain) NSArray * titleTop;



/**
* 一维柱状图
*
* @param frame
* @param datas 支持一维数组
* @param titleX nil显示下标
* @param color 可以是NSArray , 可以是UIColor , 可以是nil==蓝色(默认)
*
* @return 柱状图
*/
-(instancetype)initWithFrame:(CGRect)frame
data:(NSArray*)datas
title:(NSArray*)titleX
color:(id)color;



/**
* 多维柱状图
*
* @param frame
* @param datas 支持多维数组
* @param titleX nil显示下标
* @param colors 只能是数组
*
* @return 柱状图
*/
-(instancetype)initWithFrame:(CGRect)frame
datas:(NSArray*)datas
titles:(NSArray*)titleX
colors:(NSArray*)colors;



/**
* 用于修改参数以后 , 重绘
*/
-(void)show;
@end
149 changes: 149 additions & 0 deletions toone/Classes/3rd/SGChart/SGBarChart.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
//
// SGBarChart.m
// bar自定义
//
// Created by apple on 16/5/13.
// Copyright © 2016年 jzs.com. All rights reserved.
//

#import "SGBarChart.h"
#import "SGBarSuper.h"
#import "SGSign.h"
#import "SGConst.h"


@interface SGBarChart()
@property (nonatomic,retain) UIScrollView * sc;
@property (nonatomic,retain) SGBarSuper * bar;
@property (nonatomic,retain) id color;
@property (nonatomic,retain) NSArray * colors;
@property (nonatomic,assign) int sign; //标记
@end
@implementation SGBarChart



-(instancetype)initWithFrame:(CGRect)frame
data:(NSArray*)datas
title:(NSArray*)titleX
color:(id)color{
_sign = 1;
_datas = datas;
_titleX = titleX;
_color = color;


if (_titleX.count != _datas.count && _titleX) {
NSLog(@"title匹配错误");
}
if ([_color isKindOfClass:[NSArray class]] && _color) {
if ([(NSArray*)_color count] != _datas.count) {
NSLog(@"color匹配错误");
}
}else{
if (![_color isKindOfClass:[UIColor class]]) {
NSLog(@"color is not UIColor class , color = %@",_color);
}
}

self = [super initWithFrame:frame];
if (self) {
[self views];
}
return self;
}
-(instancetype)initWithFrame:(CGRect)frame
datas:(NSArray*)datas
titles:(NSArray*)titleX
colors:(NSArray*)colors{
_sign = 2;
_datas = datas;
_titleX = titleX;
_colors = colors;
if (_titleX.count != _datas.count && _titleX) {
NSLog(@"titles匹配错误");
}
if (_datas[0]) {
if (colors.count != [(NSArray*)_datas[0] count]) {
NSLog(@"colors匹配错误");
}
}
self = [super initWithFrame:frame];
if (self) {
[self views];
}
return self;
}
-(void)views{
CGFloat x = 0;
CGFloat y = titleTop_height;
CGFloat w = self.frame.size.width;
CGFloat h = self.frame.size.height-titleTop_height;
_sc = [[UIScrollView alloc] initWithFrame:CGRectMake(x, y,w, h)];
[self addSubview:_sc];
[self show];
}
-(void)show{
[self remove];
switch (_sign) {
case 1:
_bar = [[SGBarSuper alloc] initWithFrame:_sc.frame
data:_datas
title:_titleX
color:_color];
break;
case 2:
_bar = [[SGBarSuper alloc] initWithFrame:_sc.frame
datas:_datas
titles:_titleX
colors:_colors];
break;
default:
break;
}

if (_bar.sectionWidth * _datas.count < _sc.frame.size.width) {
_bar.center = CGPointMake(_sc.frame.size.width/2, _sc.frame.size.height/2);
}
_sc.contentSize = CGSizeMake(_bar.frame.size.width, _sc.frame.size.height);
[_sc addSubview:_bar];
}
/*
重新赋值
*/
-(void)setDatas:(NSArray *)datas{
_datas = datas;
}
-(void)setTitleX:(NSArray *)titleX{
_titleX = titleX;
}
-(void)setTitleTop:(NSArray *)titleTop{
for (UIView * view in self.subviews) {
if ([view isKindOfClass:[SGSign class]]) {
[view removeFromSuperview];
}
}
for (long i=0; i<titleTop.count; ++i) {
CGFloat x = self.frame.size.width-titleSign_width*(i+1);
CGFloat y = 0;
CGFloat w = titleSign_width;
CGFloat h = titleTop_height;
SGSign * sign_view = [[SGSign alloc] initWithFrame:CGRectMake(x, y, w, h)];
sign_view.color= _sign == 1 ?
([_color isKindOfClass:[UIColor class]] ? _color : [UIColor blueColor]):
([_colors isKindOfClass:[NSArray class]] ? _colors[_colors.count-i-1] : [UIColor blueColor]);
sign_view.title = titleTop[titleTop.count-i-1];
[self addSubview:sign_view];
}
}
/*
移除
*/
-(void)remove{
if (_bar) {
[_bar removeFromSuperview];
_bar = nil;
}
}

@end
Loading